In this post We will be going to set up the system for voice recognition and voice generation.
Before delving into the details, lets structure our work space. Lets create a folder structure that will hold our project, but first we need to give a name to our assistant. In my case I will call her Ayda ans I will give her a female voice and personality,
I have the following folder structure on my computer for this project:
Choosing an STT engine
An STT engine is basically a piece of software that transforms speech text. We will use an existing engine into our application. There exists a large variety of STT engines:
- Pocketsphinx: open-source speech decoder by the CMU Sphinx project. Unfortunately, the recognition rate is not the best but will be performed offline.
- Google STT: the speech-to-text system by Google. It is the same software a powers OK, Google. There is a limited number of request per day and needs an active internet connection.
- AT&T STT similar ro Google Speech, it also performs decoding online and thus needs an active internet connection.
- IBM STT : part of Watson and similar to google, you’ll also need an active internet connection.
I opted for Google STT as a backend for my speech to text component.
It turned out that getting this functionality is fairly simple once the mentioned libraries are installed.
create a file called stt.py. We create a function listen(). The role of this function is to listen to the speech, send it to google and return the result to the calling function.
import speech_recognition as sr def listen(): # obtain audio from the microphone r = sr.Recognizer() with sr.Microphone() as source: print("Say something!") audio = r.listen(source) text=None # recognize speech using Google Speech Recognition try: # for testing purposes, we're just using the default API key # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")` # instead of `r.recognize_google(audio)` text= r.recognize_google(audio) except sr.UnknownValueError: print("Google Speech Recognition could not understand audio") except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e)) return text
Text to speech
The second component for our virtual assistant is the ability to talk. for this purpose we will use a TTS engine. There are different engine available for all the platforms. Fortunately in my case OSX comes with this component already installed.
To test the say command, open the command line and enter the following command:
$ say "Hi, I am Ayda"
As speech is a way to affect the external world, this function will go inside Affectors folder. create a file named tts.py.
The following code will accomplish this task.
import os import sys def say(message): """ This function takes a message as an argument and converts it to speech depending on the OS. """ if sys.platform == 'darwin': return os.system('say ' + message)
Now lets modify the main function to integrate this new function.
from Sensors import stt from Affectors import tts def main(): speech_text=stt.listen() print(speech_text) tts.tts(speech_text) main()
This simple programme will simply repeat what you you say.
We surely need to improve our programme, but for now we have all the required functionalities to interact by voice with our assistant.
In this great design of things you receive a B- for hard work. Exactly where you actually confused us was on your details. You know, people say, the devil is in the details… And it could not be more accurate in this article. Having said that, let me say to you what exactly did do the job. Your writing is certainly really persuasive and this is most likely the reason why I am taking an effort in order to comment. I do not make it a regular habit of doing that. Second, although I can certainly see a leaps in reason you make, I am not really confident of just how you seem to unite your points which in turn make the final result. For right now I will yield to your position however wish in the future you actually connect your dots better.
I like it when folks come together and share ideas. Great site, stick with it!
Aw, this was an incredibly good post. Finding the time and actual effort to generate a great article… but what can I say… I hesitate a whole lot and don’t seem to get anything done.
May I simply say what a comfort to find an individual who really understands what they are discussing on the internet. You actually know how to bring an issue to light and make it important. More and more people have to read this and understand this side of the story. I can’t believe you’re not more popular given that you surely have the gift.
Terrific work! That is the type of information that are meant to be shared across the web. Shame on the seek engines for no longer positioning this submit higher! Come on over and consult with my website . Thanks =)
Hi my friend! I want to say that this article is amazing, nice written and include approximately all important infos. I’d like to see more posts like this.
I just want to mention I’m new to blogging and site-building and really loved your blog. Most likely I’m going to bookmark your blog post . You really have tremendous writings. Thank you for sharing your webpage.