【问题标题】:Python speech_recognition for desktop apps用于桌面应用程序的 Python Speech_recognition
【发布时间】:2021-01-02 09:44:18
【问题描述】:

我一直在尝试使用speech_recognition 库在桌面上收听音频,但不知道如何实现它...

例如: 假设我们在后台播放 YouTube 视频,如何将语音(在桌面背景中)转换为文本?

【问题讨论】:

    标签: python speech-recognition


    【解决方案1】:

    试试这个

    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  
    
    
    

    【讨论】:

      猜你喜欢
      • 2014-03-09
      • 1970-01-01
      • 1970-01-01
      • 2015-10-06
      • 1970-01-01
      • 2012-05-04
      • 2011-08-04
      • 1970-01-01
      • 2013-01-25
      相关资源
      最近更新 更多