首页 > 解决方案 > 虚拟助手的语音指令无响应

问题描述

我从这个 YouTube 视频 ( https://www.youtube.com/watch?v=AGatX_8gaeM )开始制作一个虚拟助手程序。我制作了基本的语音识别代码,但它没有响应对内部麦克风和外部麦克风的语音输入。当我运行程序时

import speech_recognition as sr
from gtts import gTTS

def recordAudio():
   record=sr.Recognizer()

   with sr.Microphone() as source:
      print('Say something!')
      audio=record.listen(source)

   data=''

   try:
      data=record.recognize_google(audio)
      print('You said: {}'.format(data))

   except sr.UnknownValueError:
      print('Ran into some unknown error retry....')
      recordAudio()

   except sr.RequestError:
      print('Ran into request error retry....')
      recordAudio()

   except:
      print('Ran into something other than UnknownValueError or RequestError')


recordAudio()

但这会发生:

ALSA lib pcm_dsnoop.c:641:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_a52.c:823:(_snd_pcm_a52_open) a52 is only for playback
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
Say something!

和命令

import speech_recognitioin as sr
sr.Microphone.list_microphone_names()

返回这个:

ALSA lib pcm_dsnoop.c:641:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_a52.c:823:(_snd_pcm_a52_open) a52 is only for playback
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card

ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
['HD-Audio Generic: HDMI 0 (hw:0,3)', 'HD-Audio Generic: ALC236 Analog (hw:1,0)', 'hdmi', 
'pulse', 'default']

有人可以帮我解决这个问题。

标签: python-3.xspeech-recognitiongtts

解决方案


您必须在笔记本电脑或 PC 上连接麦克风因为通过语音提供输入需要麦克风


推荐阅读