亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用于桌面應用程序的 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 關注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號