使用SpeechRecognition转录系统音频

时间:2020-07-27 15:06:06

标签: python audio speech-recognition speech-to-text

尝试转录系统音频(Youtube流,Twitch流,Spotify等)

该代码很简单,并且可以与我的外接麦克风配合使用,但是我很难使它脱离系统音频。我确定了与Audacity匹配的正确Device_Index,但是当它与该通道一起运行时,出现错误“ OSError:[Errno -9998]无效的通道数”。

我的常规麦克风正常工作: 2个麦克风阵列(Realtek Audio,MME(2进0出)

我认为系统音频不起作用: 13个扬声器(DisplayLink音频),Windows WASAPI(0进2出)

我猜我走错了路。如果有人可以向正确的方向推动我,我将不胜感激。

import speech_recognition as sr  

r = sr.Recognizer()                                                                                   
with sr.Microphone(device_index=25) as source:                                                                       
    print("Speak:")                                                                                   
    audio = r.listen(source)   

try:
    print("\"" + r.recognize_google(audio)+"\"")
except sr.UnknownValueError:
    print("Could not understand audio")
except sr.RequestError as e:
    print("Could not request results; {0}".format(e))

整个设备索引:

   0 Microsoft Sound Mapper - Input, MME (2 in, 0 out)
>  1 Stereo Mix (Realtek Audio), MME (2 in, 0 out)
   2 Microphone Array (Realtek Audio, MME (2 in, 0 out) ---WORKS---
   3 Microsoft Sound Mapper - Output, MME (0 in, 2 out)
<  4 Speakers (DisplayLink Audio), MME (0 in, 2 out)
   5 Speakers / Headphones (Realtek , MME (0 in, 2 out)
   6 Primary Sound Capture Driver, Windows DirectSound (2 in, 0 out)
   7 Stereo Mix (Realtek Audio), Windows DirectSound (2 in, 0 out)
   8 Microphone Array (Realtek Audio), Windows DirectSound (2 in, 0 out)
   9 Primary Sound Driver, Windows DirectSound (0 in, 2 out)
  10 Speakers (DisplayLink Audio), Windows DirectSound (0 in, 2 out)
  11 Speakers / Headphones (Realtek Audio), Windows DirectSound (0 in, 2 out)
  12 Realtek ASIO, ASIO (2 in, 2 out)
  13 Speakers (DisplayLink Audio), Windows WASAPI (0 in, 2 out)
  14 Speakers / Headphones (Realtek Audio), Windows WASAPI (0 in, 2 out)
  15 Stereo Mix (Realtek Audio), Windows WASAPI (2 in, 0 out) ---COULD NOT UNDERSTAND AUDIO---
  16 Microphone Array (Realtek Audio), Windows WASAPI (2 in, 0 out) ---WORKS---
  17 Headphones (), Windows WDM-KS (0 in, 2 out)
  18 Microphone Array (Realtek HD Audio Mic Array input), Windows WDM-KS (2 in, 0 out)
  19 Stereo Mix (Realtek HD Audio Stereo input), Windows WDM-KS (2 in, 0 out)
  20 Speakers (Realtek HD Audio output with SST), Windows WDM-KS (0 in, 2 out)
  21 Jack Mic (Realtek HD Audio Front Mic input), Windows WDM-KS (2 in, 0 out)
  22 Speakers (DisplayLink Audio), Windows WDM-KS (0 in, 6 out)
  23 Microphone (DisplayLink Audio), Windows WDM-KS (2 in, 0 out)
  24 Headset (@System32\drivers\bthhfenum.sys,#2;%1 Hands-Free AG Audio%0

0 个答案:

没有答案