Python Forum

Full Version: speech converstions on live audio stream
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to throw the speech to text conversions on my console when the user has stopped speaking. For it I installed speech_recognition module and python2.

When I run on command line
python -m speech_recognition
it is able to detect the end of the user speech, convert it and print it on my console and returning back to listen the audio from mic until I stop it. I am not sure which converter it is using. The output is accurate enough

Output:
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map Cannot connect to server socket err = No such file or directory Cannot connect to server request channel jack server is not running or cannot be started JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for 4294967295, skipping unlock JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for 4294967295, skipping unlock A moment of silence, please... Set minimum energy threshold to 1806.92166802 Say something! Got it! Now to recognize it... I am testing this speech converters. I am done ! Say something! Got it! Now to recognize it... The second tw test going on.
Now I am trying to do speech recognition through controlled way, using the code snippets examples given and I have choosen microsoft bing for converstions.

def convert_speech_to_text(audio):
	
	message = sr.Recognizer().recognize_bing(audio, key=BING_KEY)
	return(message)

while True:
    # try: 
	with sr.Microphone() as source:
		sr.Recognizer().adjust_for_ambient_noise(source)
		print(1,'say')
		audio = sr.Recognizer().listen(source)
		
	print("Converting")
	message = convert_speech_to_text(audio)
	print(message)
    # except: 
       # print("error")
my program works fine with out while loop, but when using it, it is stuck by printing (1,'say') and it is continuosly listening to the mic and not converting.

Is there any way I can reproduce the command
python -m speech_recognition
does as .py file?
probably you can try

with sr.Microphone() as source:
    sr.Recognizer().adjust_for_ambient_noise(source)
    print(1,'say')
    while True:
        audio = sr.Recognizer().listen(source)
        print("Converting")
        message = convert_speech_to_text(audio)
        print(message)