# Make Your BBC Micro:Bit Talk Using MicroPython

<span class="s"></span>

# Make Your BBC Micro:Bit Talk Using MicroPython


Hello Everyone!

Hope you all are doing well. Today, I am going to show how to make your micro:bit talk using a very easy programming language that is MicroPython.Yes, it is very easy to make your BBC Micro:bit device talk using Speech Synthesis. And you know. the interesting part is just four lines of code and your device will start talking/saying whatever you want.

So. let’s see how to do this.

If you don’t know whatBBC Mic<span id="rmm"><span id="rmm">r</span></span>o:bit is and how to get started with it, please see [My article](http://www.c-sharpcorner.com/article/getting-started-with-bbc-microbit/) or [this article](http://www.c-sharpcorner.com/article/display-your-name-on-micro-bit-using-micro-python/), where I have covered all the basics on how to get started with Micro:bit.

So, let’s get started and see how to make micro:bit talk.

**Prerequisites**

1.  Micro: bit (1 pcs)
2.  USB cable (1 pcs)
3.  Battery AAA 1.5V (2 pcs)
4.  Battery Box (1 pcs)
5.  Speaker
6.  Crocodile connectors or normal wire

![Image for post](https://miro.medium.com/max/60/0*xf9i0OLPI0qonLoS.jpg?q=20)

<noscript><img alt="Image for post" class="fg ev er iw w" src="https://miro.medium.com/max/1264/0*xf9i0OLPI0qonLoS.jpg" width="632" height="603" srcSet="https://miro.medium.com/max/552/0*xf9i0OLPI0qonLoS.jpg 276w, https://miro.medium.com/max/1104/0*xf9i0OLPI0qonLoS.jpg 552w, https://miro.medium.com/max/1264/0*xf9i0OLPI0qonLoS.jpg 632w" sizes="632px"/></noscript>

**Connection**

Before getting started, first we need to know how to connect our micro:bit to speaker.

For Speech Synthesis in Micro: bit, we need to connect the micro: bit _PIN0_ and _PIN1_ to our speaker because for Speech synthesis, it always produces output from _PIN0_ and _PIN1_ only. From PIN 0 andPIN 1, you can connect any end to your speaker jack either positive or negative that really doesn’t matter.

![Image for post](https://miro.medium.com/max/60/0*o8wTT60UvFL28FfR.png?q=20)

<noscript><img alt="Image for post" class="fg ev er iw w" src="https://miro.medium.com/max/912/0*o8wTT60UvFL28FfR.png" width="456" height="448" srcSet="https://miro.medium.com/max/552/0*o8wTT60UvFL28FfR.png 276w, https://miro.medium.com/max/912/0*o8wTT60UvFL28FfR.png 456w" sizes="456px"/></noscript>

And, this is how your connection will look like. Do not forget to connect to your computer via USB cable.

![Image for post](https://miro.medium.com/max/60/0*t8VD5HE3-s5purJw.jpg?q=20)

<noscript><img alt="Image for post" class="fg ev er iw w" src="https://miro.medium.com/max/1300/0*t8VD5HE3-s5purJw.jpg" width="650" height="650" srcSet="https://miro.medium.com/max/552/0*t8VD5HE3-s5purJw.jpg 276w, https://miro.medium.com/max/1104/0*t8VD5HE3-s5purJw.jpg 552w, https://miro.medium.com/max/1280/0*t8VD5HE3-s5purJw.jpg 640w, https://miro.medium.com/max/1300/0*t8VD5HE3-s5purJw.jpg 650w" sizes="650px"/></noscript>

I had no crocodile connectors and I was very excited to see my micro:bit talking, so I used normal wires to make the connections. Anyway, this is the connection.

Now, let us see the coding part. For coding, we have two options — Online and Offline.

**Online**

If you want to use online IDE for MicroPython, then you can visit this [link](http://microbit.co.uk/app) of BBC Micro:bit [official site](http://microbit.co.uk/app). Click on “Create code” and then choose “MicroPython”.

![Image for post](https://miro.medium.com/max/60/0*NzK00V5LuATY3DjY.PNG?q=20)

<noscript><img alt="Image for post" class="fg ev er iw w" src="https://miro.medium.com/max/1300/0*NzK00V5LuATY3DjY.PNG" width="650" height="623" srcSet="https://miro.medium.com/max/552/0*NzK00V5LuATY3DjY.PNG 276w, https://miro.medium.com/max/1104/0*NzK00V5LuATY3DjY.PNG 552w, https://miro.medium.com/max/1280/0*NzK00V5LuATY3DjY.PNG 640w, https://miro.medium.com/max/1300/0*NzK00V5LuATY3DjY.PNG 650w" sizes="650px"/></noscript>

**Offline**

For offline, we are going to use [MU](https://codewith.mu/) editor for Micro:bit. Why I am using this because it is very light-weight and easy to use. The best part is that we can directly flash from editor IDE to our Micro:bit. We need not to copy and paste Hex file again and again whenever we update the code. You can download [here](https://codewith.mu/#download). For Windows, you need to install one [driver](https://developer.mbed.org/handbook/Windows-serial-configuration) also to flash directly to your micro:bit whenever you update the code.[download here](https://developer.mbed.org/handbook/Windows-serial-configuration). So go to [https://codewith.mu/#download,](https://codewith.mu/#download,) and download and install.

![Image for post](https://miro.medium.com/max/60/0*9kvDSeimnOiRsGwV.PNG?q=20)

<noscript><img alt="Image for post" class="fg ev er iw w" src="https://miro.medium.com/max/1300/0*9kvDSeimnOiRsGwV.PNG" width="650" height="652" srcSet="https://miro.medium.com/max/552/0*9kvDSeimnOiRsGwV.PNG 276w, https://miro.medium.com/max/1104/0*9kvDSeimnOiRsGwV.PNG 552w, https://miro.medium.com/max/1280/0*9kvDSeimnOiRsGwV.PNG 640w, https://miro.medium.com/max/1300/0*9kvDSeimnOiRsGwV.PNG 650w" sizes="650px"/></noscript>

Let us write the code.

I am going to add a micro:bit and _Speech_ library by writing the following code.

> from microbit import *
> 
> import speech

The above code actually means that we want to use all the objects and functions/methods that are available within the micro: bit library, like controlling the led display, displaying our name, displaying symbols, Speech Synthesis, music and much more. Speech is a class there and now we are going to call say() method to make our micro: bit talk by writing the following code.

> _speech.say(“Hello,CSHARP”)_

In the above code, _Speech_ is a class and we are calling _say_ method and passing _Hello CSHARP as String._It takes String as a parameter_._ Now, if we will run this code, our micro: bit will speak _Hello CSHARP._

We can add a few more things to this code like,

**Pitch _—_** how high or low the voice sounds (0 = high, 255 = Barry White).

Speed **_—_** how quickly the device talks (0 = impossible, 255 = bedtime story)

**Mouth** — how tight-lipped or overly enunciating the voice sounds (0 = ventriloquist’s dummy, 255 = Foghorn Leghorn)

**Throat** — how relaxed or tense is the tone of voice (0 = falling apart, 255 = totally chilled)

These parameters control the quality of sound — a.k.a. the timbre. To be honest, the best way to get the tone of voice you want is to experiment, use your judgment, and adjust. To learn more visit [here](https://microbit-micropython.readthedocs.io/en/latest/tutorials/speech.html).

After adding these parameters, our code looks like the following.

> speech.say(“Hello,CSHARP”,speed=120, pitch=100, throat=100, mouth=200)

And yes, if we want our micro: bit say multiple things, then we can add delay also.

> speech.say(“Hello,FACEBOOK”)
> 
> sleep(2000)
> 
> speech.say(“Hello,I AM MICROBIT AND I CAN TALK”)
> 
> sleep(2000)

I want my micro:bit say a lot of things, so here is the code and this is final code.

> from microbit **import** *
> 
> **import** speech
> 
> display.show(Image.HAPPY)
> 
> sleep(2000)
> 
> speech.say(“Hello,Twitter”)
> 
> sleep(2000)
> 
> display.show(Image.HEART)
> 
> sleep(2000)
> 
> speech.say(“Hello,CSHARP”)
> 
> sleep(2000)
> 
> speech.say(“Hello,FACEBOOK”)
> 
> sleep(2000)
> 
> speech.say(“Hello,I AM MICROBIT AND I CAN TALK”)
> 
> sleep(2000)
> 
> speech.say(“I LOVE YOU”)

Get full code [Here](https://github.com/anishansari/Microbit-Speech-Sysntheis).

Now, after writing the code, let us see how can we flash it and run our code on micro:bit. For this, after writing the code, just click on “Flash” button there.

![Image for post](https://miro.medium.com/max/60/0*9bZ2sEe4d5eApypd.PNG?q=20)

<noscript><img alt="Image for post" class="fg ev er iw w" src="https://miro.medium.com/max/1300/0*9bZ2sEe4d5eApypd.PNG" width="650" height="650" srcSet="https://miro.medium.com/max/552/0*9bZ2sEe4d5eApypd.PNG 276w, https://miro.medium.com/max/1104/0*9bZ2sEe4d5eApypd.PNG 552w, https://miro.medium.com/max/1280/0*9bZ2sEe4d5eApypd.PNG 640w, https://miro.medium.com/max/1300/0*9bZ2sEe4d5eApypd.PNG 650w" sizes="650px"/></noscript>

The demo can be seen [here](https://youtu.be/ftWqacfXnZ8).

<a href="https://www.buymeacoffee.com/anishansari" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
