realtimerecognize.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:audiolearning 作者: jingwang3235 项目源码 文件源码
def listen_translate():
    while(True):
        # obtain audio from the microphone
        r = sr.Recognizer()
        with sr.Microphone(sample_rate=8000) as source:
            print("Say something!")
    #         print(5),
    #         time.sleep(1)
    #         print(4),
    #         time.sleep(1)
    #         print(3),
    #         time.sleep(1)
    #         print(2),
    #         time.sleep(1)  
    #         print(1),     
    #         time.sleep(1)  
            audio = r.listen(source)#,timeout=5,phrase_time_limit=0.05

    #     r = sr.Recognizer()
    #     with sr.AudioFile('./english.wav') as source:
    #         audio = r.record(source)  # read the entire audio file

        # write audio to a WAV file    ``
with open("microphone-results.wav", "wb") as f:
        f.write(audio.get_wav_data())

    # recognize speech using Sphinx
    try:
        print("Sphinx thinks you said :" + r.recognize_sphinx(audio))
    except sr.UnknownValueError:
        print("Sphinx could not understand audio")
    except sr.RequestError as e:
        print("Sphinx error; {0}".format(e))

```

评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号