Python Forum
Continous Speech Recognition - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Continous Speech Recognition (/thread-30641.html)



Continous Speech Recognition - dell91 - Oct-29-2020

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