Python语音识别库会在Windows上切断不协调或缩放的扬声器输出

2024-04-19 04:05:03 发布

您现在位置:Python中文网/ 问答频道 /正文

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

  1. 加入Zoom或Discord通话组,确保您能听到通话中的其他人
  2. 使用基本语音识别代码,如下所示
  3. 现在再也听不到别人在叫了

离开并重新进入解决了问题,在第2步音频切断后更改扬声器输出也解决了问题

下面是一些基本代码。请注意,在某个时候,我确实发现这种方法在不和谐通话中没有切断音频,所以我猜在他们这一端有一些间歇性的东西——我只是想弄清楚如何在我这一端很好地处理它

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")

Tags: 代码sourceas步骤语音音频audiocommand