gTTS with python not working
04:02 27 Jul 2017

I am working on a speech recognition project using gTTS. The problem is, when i run the code, the system doesn't respond to it. (It won't answer to my query) I tried as per my knowledge but couldn't solve it. I would really appreciate if anyone could help me fix this. Thanks very much in advance. Here is my code:

import speech_recognition as sr
from time import ctime
import time
import os
import pyaudio
from gtts import gTTS


def speak(audioString):
    print(audioString)
    tts = gTTS(text=audioString, lang='en')
    tts.save("audio.wav")
    os.system("audio.wav")


def recordaudio():
    # Record Audio
    r = sr.Recognizer()
    with sr.Microphone() as source:
        r.adjust_for_ambient_noise(source)
        print("Say something!")
    audio = r.listen(source)
    time.sleep(2)
    # Speech recognition using Google Speech Recognition
    data = ""
    try:
        data = r.recognize_google(audio)
        print("You said: " + data)
    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 data


def ADA(data):
    if "how are you" in data:
        speak("I am fine")

    if "what time is it" in data:
        speak(ctime())

    if "What is your name" in data:
        speak("Call me ADA.")

    if "where is" in data:
        data = data.split(" ")
        location = data[2]
        speak("Hold on Sir, I will show you where " + location + " is.")
        os.system("chromium-browser https://www.google.nl/maps/place/" + location + "/&")


# initialization
time.sleep(2)
speak("Hi Touseef, what can I do for you?")
while 1:
   data = recordaudio()
   ADA(data) 

I have tested the speechrecognition and gtts libraries separately to check if they are working or not. There is nothing wrong with both of them. But when I try to use them in my actual code, something goes wrong and I can't figure it out.

Here are the code snippets for the libraries.

gTTS

from gtts import gTTS
import os
tts = gTTS(text='Helllo, Good morning my name is ADA. How can I help you?', lang='en')
tts.save("good.mp3")
os.system("good.mp3")

SpeechRecognition

import speech_recognition as sr

r = sr.Recognizer()
with sr.Microphone() as source:
    r.adjust_for_ambient_noise(source) 
    print("Say something!")
    audio = r.listen(source)


try:
   print(r.recognize_google(audio))
except sr.UnknownValueError:
   print("Could not understand audio")
except sr.RequestError as e:
   print("Could not request results from Google Speech Recognition service; {0}".format(e))

I'm a student and this is my academic project. Please somebody help me figure this out.

python speech-recognition text-to-speech speech-to-text