---
title: "Let's use Google Speech to control the device"
url: "https://maker.wiznet.io/louis_m/projects/lets-use-google-speech-to-control-the-device/"
markdown_url: "https://maker.wiznet.io/louis_m/projects/lets-use-google-speech-to-control-the-device/md"
type: "WCC: WIZnet Created Content"
author: "Louis"
author_url: "https://maker.wiznet.io/louis_m/"
original_author: "Louis"
original_url: "https://www.hackster.io/louis_m/let-s-use-google-speech-to-control-the-device-bd58b3"
published: "2022-12-15"
language: "en"
hardware: ["Raspberry Pi 4 Model B", "WIZnet W5100S", "Adafruit NeoPixel Ring: WS2812 5050 RGB LED"]
likes: 8
views: 706
comments: 2
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Let's use Google Speech to control the device

> Use Google Speech-to-Text API to convert voice to text and then control the device.

Original author: Louis (source: https://www.hackster.io/louis_m/let-s-use-google-speech-to-control-the-device-bd58b3)

## Components

- **Raspberry Pi 4 Model B** x 1 ([docs](https://datasheets.raspberrypi.com/rpi4/raspberry-pi-4-product-brief.pdf))
- **WIZnet W5100S** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5100S))
- **Adafruit NeoPixel Ring: WS2812 5050 RGB LED** x 1 ([docs](https://www.adafruit.com/product/1586))

## Documents and links

- [code](https://maker.wiznet.io/_lib/download.asp?path=project/3921&downfile=wiznet%5Fspeak%2Epy) (code)
- [code_pico](https://maker.wiznet.io/_lib/download.asp?path=project/3921&downfile=code%2Epy) (code)

## Article

### **OverviewGoogle's Speech-to-Text** is a simple API based on machine learning that applies a powerful neural network model. Convert your voice to a string using the google.cloud.speech library. The converted string communicates with the **W5100S** via MQTT and controls the **NeoPixel**.

![](https://maker.wiznet.io/upload/ckeditor5/298547281%5F1671136746%2Egif)

### **Prepare**

> **Google** Speech-to-Text

Speech-to-Text is an API that is powered by Google's artificial intelligence (AI) technology. You send your audio data to Speech-to-Text, then receive a text transcription of your audio data in response. For more information about how to construct a Speech-to-Text request, see the [requests](https://cloud.google.com/speech-to-text/docs/speech-to-text-requests)page.

<https://cloud.google.com/speech-to-text/docs/before-you-begin?hl=en>

Enable Speech-to-Text on a project.

- Make sure billing is enabled for Speech-to-Text.

- Make sure your project has at least one service account.

- Download a service account credential key.

![](https://hackster.imgix.net/uploads/attachments/1536567/image_31VH2FiEV2.png?auto=compress%2Cformat&w=740&h=555&fit=max)

> **Connect Raspberry Pi**

![](https://hackster.imgix.net/uploads/attachments/1536518/image_PNyVJQmVff.png?auto=compress%2Cformat&w=740&h=555&fit=max)

![](https://hackster.imgix.net/uploads/attachments/1536540/image_c4R1Ncqd3E.png?auto=compress%2Cformat&w=740&h=555&fit=max)

Check out our step-by-step guide:
[How to set up your Raspberry Pi 4 for the first time](https://magpi.raspberrypi.com/books/beginners-guide-4th-ed)

> **Connect W5100S-EVB-Pico**

![](https://hackster.imgix.net/uploads/attachments/1536521/image_rxHCXipAjC.png?auto=compress%2Cformat&w=740&h=555&fit=max)

W5100S-EVB-Pico is a microcontroller evaluation board based on the Raspberry Pi RP2040 and fully hardwired TCP/IP controller W5100S – and basically works the same as Raspberry Pi Pico board but with additional Ethernet via W5100S.

### **Setup Google API service**

![](https://hackster.imgix.net/uploads/attachments/1536574/image_Ryj7NWVxaB.png?auto=compress%2Cformat&w=740&h=555&fit=max)

In this tutorial, you'll learn how to use the Speech-to-Text V1 API from a Python application by following these steps:

Select a Google Cloud project and enable the Speech-to-Text API.

- Select a Google Cloud project and enable the Speech-to-Text API.

Set up authentication by creating a service account and downloading a key.

- Set up authentication by creating a service account and downloading a key.

Create a sample application that transcribes an audio file to text.

- Create a sample application that transcribes an audio file to text.

Estimated time to complete: To get started, click [**Start**](https://console.cloud.google.com/freetrial/signup/tos?_ga=2.193169323.722706232.1670989453-1493226483.1670219256&_gac=1.19213836.1670310478.EAIaIQobChMIpYTSyePh-wIVCqqWCh1tHwffEAAYASAAEgIELPD_BwE&facet_utm_source=google&facet_utm_campaign=%28organic%29&facet_utm_medium=organic&facet_url=https:%2F%2Fcloud.google.com%2Fspeech-to-text&facet_id_list=%5B39300012,%2039300022,%2039300118,%2039300191,%2039300195,%2039300241,%2039300319,%2039300320,%2039300325,%2039300333,%2039300346,%2039300354,%2039300364,%2039300373,%2039300412,%2039300422,%2039300434%5D).

> **Creating a project on the Google Cloud platform&lt;step-1>Menu -> IAM & Admin -> Manage resources**

![](https://hackster.imgix.net/uploads/attachments/1537149/image_88Y7306VBj.png?auto=compress%2Cformat&w=740&h=555&fit=max)

**&lt;step-2>** Go to the page **[Manage Resources]** and **[+CREATE PROJECT]** select.

![](https://hackster.imgix.net/uploads/attachments/1537105/image_Angg9jmXkO.png?auto=compress%2Cformat&w=740&h=555&fit=max)

**&lt;step-3>** Enter a name for the project and press **CREATE.** This creates a project.

![](https://hackster.imgix.net/uploads/attachments/1537148/image_dfMcQD6ONH.png?auto=compress%2Cformat&w=740&h=555&fit=max)

**&lt;step-4>Menu -> APIs & servuce-> Library**

![](https://hackster.imgix.net/uploads/attachments/1537146/image_9KmizvlAUF.png?auto=compress%2Cformat&w=740&h=555&fit=max)

**&lt;step-5>[Cloud Speech-to-Text API]** Find and click. **[MANAGE]** click

![](https://hackster.imgix.net/uploads/attachments/1537142/image_7oLfuR2jA7.png?auto=compress%2Cformat&w=740&h=555&fit=max)

![](https://hackster.imgix.net/uploads/attachments/1537144/image_1GZIjzrgMb.png?auto=compress%2Cformat&w=740&h=555&fit=max)

> **Create User Credentials&lt;step-1>[+CREATE CREDENTIALS]** select and **Service account** click

![](https://hackster.imgix.net/uploads/attachments/1537154/image_jqgBGF63wu.png?auto=compress%2Cformat&w=740&h=555&fit=max)

**&lt;step-2>** Enter a name for the account and press **CREATE**

![](https://hackster.imgix.net/uploads/attachments/1537158/image_WkK3CsSP6L.png?auto=compress%2Cformat&w=740&h=555&fit=max)

**&lt;step-3>** Verify that the service account has been created as follows:

![](https://hackster.imgix.net/uploads/attachments/1537159/image_enIrhUmbpe.png?auto=compress%2Cformat&w=740&h=555&fit=max)

> **Create APIkey&lt;step-1>Manage service accounts** click. Enter the service account you just created.

![](https://hackster.imgix.net/uploads/attachments/1537162/image_XpvoQaBg3d.png?auto=compress%2Cformat&w=740&h=555&fit=max)

**&lt;step-2>KEYS -> ADD KEY -> Create new key**

![](https://hackster.imgix.net/uploads/attachments/1537163/image_4O7v22krnW.png?auto=compress%2Cformat&w=740&h=555&fit=max)

**&lt;step-3>** Press Create while selected as the **JSON** format.

![](https://hackster.imgix.net/uploads/attachments/1537164/image_PhgnOFVMWI.png?auto=compress%2Cformat&w=740&h=555&fit=max)

**&lt;step-4>** Move the created **JSON file** to the RPi directory.

![](https://hackster.imgix.net/uploads/attachments/1537166/image_tB9IC6kl7K.png?auto=compress%2Cformat&w=740&h=555&fit=max)

**&lt;step-5>** Now it's time to **export the JSON** file.

```plaintext
example) 
pi@raspberry:~ $ export GOOGLE_APPLICATION_CREDENTIALS="KEY_STRING"
```

![](https://hackster.imgix.net/uploads/attachments/1537168/image_cUsefAWJMM.png?auto=compress%2Cformat&w=740&h=555&fit=max)

### **Getting Started**

> **Raspberry Pi Setup**

- Connect the microphone to the RPi USB port and download the Google.spech library for the Google Speech-to-Text service.

```plaintext
pi@raspberry:~ $ pip install --upgrade google-cloud-speech

or

pi@raspberry:~ $ python3 -m install --upgrade google-cloud-speech
```

![](https://hackster.imgix.net/uploads/attachments/1537171/image_y42zPs9wSp.png?auto=compress%2Cformat&w=740&h=555&fit=max)

- Next, download and run mosquitto because you will control the device through mqtt. To install the Mosquitto Broker enter these next commands:

```plaintext
pi@raspberry:~ $ sudo apt install -y mosquitto mosquitto-clients
```

To make Mosquitto auto start when the Raspberry Pi boots, you need to run the following command (this means that the Mosquitto broker will automatically start when the Raspberry Pi starts :)

```plaintext
pi@raspberry:~ $ sudo systemctl enable mosquitto.service
```

Now, test the installation by running the following command:

```plaintext
pi@raspberry:~ $ mosquitto -v
```

![](https://hackster.imgix.net/uploads/attachments/1537175/image_7WxVaFFYU2.png?auto=compress%2Cformat&w=740&h=555&fit=max)

- We will issue the data converted from Google STT to Text again in MQTT, so we will add the following command to the code. The Speech-to-Text and MQTT integrated source code is attached below.

```plaintext
mosquitto_pub -d -h mqtt_host -t mqtt_topic -m mqtt_msg
```

> **WIZnet W5100S-EVB-Pico setup**

- **Installing CircuitPython**

Install `**CircuitPython**` on Raspberry Pi Pico by referring to the link above.

<https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython/circuitpython>

- **Download the below uf2 file link on your computer**

CircuitPython 7.3.3 link - [DOWNLOAD](https://downloads.circuitpython.org/bin/raspberry_pi_pico/en_US/adafruit-circuitpython-raspberry_pi_pico-en_US-7.3.3.uf2)

- **Setup WIZnet Ethernet Library**

Copy the [**WIZnet library**](https://github.com/Wiznet/RP2040-HAT-CircuitPython)[In](https://github.com/Wiznet/RP2040-HAT-CircuitPython)to the lib folder inside the Raspberry Pi Pico. <https://learn.adafruit.com/ethernet-for-circuitpython/circuitpython-setup>

Before continuing, make sure your board's lib folder has at least the following files and folders copied over: https://github.com/Wiznet/RP2040-HAT-CircuitPython

```plaintext
adafruit_bus_device
adafruit_wiznet5k
adafrui_minimqtt
```

![](https://hackster.imgix.net/uploads/attachments/1537180/image_T8Qu48gc5Z.png?auto=compress%2Cformat&w=740&h=555&fit=max)

- **Setup NeoPixel Library**

Copy the [CircuitPython NeoPixel](https://learn.adafruit.com/circuitpython-essentials/circuitpython-neopixel) into the lib folder inside the Raspberry Pi Pico.

<https://learn.adafruit.com/circuitpython-essentials/circuitpython-neopixel>

```plaintext
adafruit_pixelbuf.mpy
neopixel.mpy
```

![](https://hackster.imgix.net/uploads/attachments/1537199/image_ABXt0qF9we.png?auto=compress%2Cformat&w=740&h=555&fit=max)

- **Install Programs**

The following serial terminal program is required for **MQTT Publish** test, download and install from below links.

✔[Tera Term](https://osdn.net/projects/ttssh2/releases/)

Before this, you should find the Raspberry Pi Pico COM port number from "**Device Manager**" on your PC.

![](https://hackster.imgix.net/uploads/attachments/1537185/image_mKSU46vpf5.png?auto=compress%2Cformat&w=740&h=555&fit=max)

> **Let's start Speech-to-Text control device**

- Paste code into **code.py **on your Raspberry Pi Pico and Save it. Press "**Ctrl+D**" on the terminal window. you can see the messages as follows

![](https://hackster.imgix.net/uploads/attachments/1537209/image_T8o8ZHfl4M.png?auto=compress%2Cformat&w=740&h=555&fit=max)

- Execute wiznet_speak.py Python code. I have attached the sauce below

![](https://hackster.imgix.net/uploads/attachments/1537210/image_8l0w2eVmTo.png?auto=compress%2Cformat&w=740&h=555&fit=max)

- Let's shout "Hi Pico" into the mic

![](https://hackster.imgix.net/uploads/attachments/1537220/image_hkjG8oYgeQ.png?auto=compress%2Cformat&w=740&h=555&fit=max)

> **Rainbow Color**

![](https://hackster.imgix.net/uploads/attachments/1537222/rainbow_xBFA4EOfUr.jpg?auto=compress%2Cformat&w=740&h=555&fit=max)

- Let's put the color we want into the microphone

![](https://hackster.imgix.net/uploads/attachments/1537223/image_pMZAppwprr.png?auto=compress%2Cformat&w=740&h=555&fit=max)

> **Color LED on**

![](https://hackster.imgix.net/uploads/attachments/1537224/image_0L8AOwow93.png?auto=compress%2Cformat&w=740&h=555&fit=max)

---

Source: https://maker.wiznet.io/louis_m/projects/lets-use-google-speech-to-control-the-device/
