Python Forum

Full Version: Continous Speech Recognition
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

I am new to this forum and also a bit new to Python to be honest.

I decided to create a project with Python where a microphone listens to a conversation and while listening it gets translated to an other language. Similar to Google Translate on Mobile.

I managed to get input from microphone using PyAudio and also write whats being said and translated to any language i want using google translate pips. At the moment i am only able to do sentence by sentence.

My problem is how should i tackle a live conversation rather than have to stop to process audio to text. Sort of one person is speaking and while the microphone is capturing data, it is being procesed.

This is my code so far:

import speech_recognition as sr
import io
from googletrans import Translator

# print(sr.Microphone.list_microphone_names())
r = sr.Recognizer()


while True:
    result = 0
    f = open("subtitles.txt", "a")
    with sr.Microphone() as source:
        print("Speak Now:")
        audio = r.listen(source)

    try:
        text = r.recognize_google(audio, language="en")
        print("You said: {}".format(text))
    except:
        print('Sorry could not recognize your voice')
        f.write("problem" + '\n')


    translator = Translator()
    result = translator.translate(text, src='en', dest='es')
    f.write(result.text + '\n')
    f.close()
Thanks a lot for your hlep