为了账号安全,请及时绑定邮箱和手机立即绑定

用于桌面应用程序的 Python 语音识别

用于桌面应用程序的 Python 语音识别

Helenr 2023-08-08 17:42:01
我一直在尝试使用库在桌面上收听音频speech_recognition,但不知道如何实现它......例如:假设我们在后台播放 YouTube 视频,如何将语音(在桌面背景中)转换为文本?
查看完整描述

1 回答

?
慕雪6442864

TA贡献1812条经验 获得超5个赞

尝试这个


import speech_recognition as sr


r = sr.Recognizer()

m = sr.Microphone()


try:

    print("A moment of silence, please...")

    with m as source: r.adjust_for_ambient_noise(source)

    print("Set minimum energy threshold to {}".format(r.energy_threshold))

    while True:

        print("Say something!")

        with m as source: audio = r.listen(source)

        print("Got it! Now to recognize it...")

        try:

            value = r.recognize_google(audio)


            if str is bytes:

                print(u"You said {}".format(value).encode("utf-8"))

            else:

                print("You said {}".format(value))

        except sr.UnknownValueError:

            print("Oops! Didn't catch that")

        except sr.RequestError as e:

            print("Uh oh! Couldn't request results from Google Speech Recognition service; {0}".format(e))

except KeyboardInterrupt:

    pass  


查看完整回答
反对 回复 2023-08-08
  • 1 回答
  • 0 关注
  • 120 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信