Python - 语音识别库导致来自 Discord 或 Zoom 的扬声器输出在 Windows 上被切断

问题描述

重现问题的步骤(似乎仅适用于 PC):

  1. 加入 Zoom 或 discord 群组通话,确保您可以听到通话中的其他人
  2. 使用基本的语音识别代码,如下所示
  3. 现在在通话中听不到其他人的声音

离开并重新进入可以解决此问题,在第 2 步中的音频切断后更改扬声器输出也是如此。

这里是一些基本的代码。请注意,在某些时候,我确实发现这可以在不切断 discord 通话中的音频的情况下工作,所以我猜他们的一端有些断断续续——我只是想弄清楚如何很好地处理它。>

import speech_recognition as sr


r = sr.Recognizer()
m = sr.Microphone()    

with m as source:
    r.adjust_for_ambient_noise(source)

    while(True):            
        
        print("Please say something...")
    
        audio = r.listen(source)
    
        command = ""
    
        try:
            # All the getting command stuff. 0 is a dummy number
            command = r.recognize_google(audio)
    
            print("You said : \n " + command)
            
            if command.lower() == "quit": break
    
        except:
            print("Error getting command from microphone")

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)