Uberi / speech_recognition

Speech recognition module for Python, supporting several engines and APIs, online and offline.
https://pypi.python.org/pypi/SpeechRecognition/
BSD 3-Clause "New" or "Revised" License
8.4k stars 2.4k forks source link

Not transcribing #675

Open saurav935 opened 1 year ago

saurav935 commented 1 year ago

Hi, I am trying out the below code:

import speech_recognition as sr

# Obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Speak now!")
    audio = r.listen(source, timeout=1,phrase_time_limit=5)

# Recognize speech using Google Speech Recognition
try:
    print("Google Speech Recognition thinks you said: " + r.recognize_google(audio))
    # convert speech to WAV file
    with open("output.wav", "wb") as f:
        f.write(audio.get_wav_data())
        print("WAV file saved successfully!")
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))

I want it to function in realtime, like whenever I say something it should convert it to text but it isn't happening. Can I get some help please?

sanqi3702 commented 11 months ago

I also have the problem, I want to let the program can recognize the speaker have spoked one sentence, then let the program goes on to recognize part. But I don't know how to solve it. I can just use 'phrase_time_limit' to let the program recognize every 15 seconds.BTW, maybe you can have a look at this one:

import speech_recognition as sr
r=sr.Recognizer()
with sr.Microphone() as source:
    print("请开始说话...")
    try:
        audio = r.listen(source, timeout=5, phrase_time_limit=15)
    except sr.WaitTimeoutError:
        print("等待超时,没有检测到音频输入")
    else:
        print('正在转录')
        text = r.recognize_google(audio, language="zh-CN")  # 将"zh-CN"替换为您的语言和地区
        print("您说的是:" + text)

This can work every 15 seconds.