STUDY/Trouble Shooting๐Ÿ”จ

[๋ผ์ฆˆ๋ฒ ๋ฆฌํŒŒ์ด4B, python] - ๋งˆ์ดํฌ ์Œ์„ฑ์ธ์‹ํ•˜๊ธฐ

JUNGY00N 2023. 11. 7. 19:41

์Œ์„ฑ์ธ์‹ in Raspberrypi with python SpeechRecognition

ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜

pip3 install SpeechRecognition

 

์—๋Ÿฌ1.

Could not import the PyAudio C module 'pyaudio._portaudio'.

AttributeError: Could not find PyAudio; check installation

sudo apt-get install -y portaudio19-dev python3-pyaudio

 

asoundrc ์„ธํŒ…ํ•˜๊ธฐ

๋‚˜์˜ ๊ฒฝ์šฐ์—๋Š” ๋งˆ์ดํฌ๋Š” card1, ์Šคํ”ผ์ปค๋Š” card2(๋ชจ๋‹ˆํ„ฐ hdmi ์‚ฌ์šฉ) 

 

$ sudo nano /usr/share/alsa/alsa.conf

 

defaults.ctl.card 0
defaults.pcm card 0

->

defaults.ctl.card 2
defaults.pcm card 1
// ๊ฐ๊ฐ ์Šคํ”ผ์ปค, ๋งˆ์ดํฌ์— ๋งž๋Š” card ๋ฒˆํ˜ธ ์ž…๋ ฅ 



pcm.rear cards.pcm.rear
pcm.centner_lfe cards.pcm.center_lfe
pcm.side cards.pcm.side 

->

pcm.rear cards.pcm.default
pcm.centner_lfe cards.pcm.default
pcm.side cards.pcm.default

 

test source 

import speech_recognition
import speech_recognition as sr


r = sr.Recognizer()

print(sr.Microphone.list_microphone_names())
mic = sr.Microphone()


with mic as source:
   print("speak!")
   r.adjust_for_ambient_noise(source)
   audio = r.listen(source, timeout = 3, phrase_time_limit = 3)


try:
   result = r.recognize_google(audio, language="ko-KR")
   print(result)
except speech_recognition.UnknownValueError:
   print("์Œ์„ฑ ์ธ์‹ ์‹คํŒจ")
except speech_recognition.RequestError:
   print("HTTP Request Error ๋ฐœ์ƒ")
except speech_recognition.WaitTimeoutError:
   print("WaitTimeout Error ๋ฐœ์ƒ")

์—๋Ÿฌ2. 

ALSA lib pcm_dmix.c:1075:(snd_pcm_dmix_open) unable to open slave

์•„๋ž˜๋Š” ๋ฌด์‹œํ•ด๋„ ๋˜๋Š” ์—๋Ÿฌ๋“ค์ด๋‹ค. (๊ฒฝ๊ณ ์ผ๋ฟ์ธ๋“ฏ)

๋”๋ณด๊ธฐ

ALSA lib pcm_dmix.c:1075:(snd_pcm_dmix_open) unable to open slave

ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.USB-Audio.pcm.hdmi.0:CARD=1,AES0=4,AES1=130,AES2=0,AES3=2'

ALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory

ALSA lib conf.c:5233:(snd_config_expand) Evaluate error: No such file or directory

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM hdmi

ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.USB-Audio.pcm.hdmi.0:CARD=1,AES0=4,AES1=130,AES2=0,AES3=2'

ALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory

ALSA lib conf.c:5233:(snd_config_expand) Evaluate error: No such file or directory

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM hdmi

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline

Cannot connect to server socket err = No such file or directory

Cannot connect to server request channel

jack server is not running or cannot be started

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

Cannot connect to server socket err = No such file or directory

Cannot connect to server request channel

jack server is not running or cannot be started

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

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:1075:(snd_pcm_dmix_open) unable to open slave

Cannot connect to server socket err = No such file or directory

Cannot connect to server request channel

jack server is not running or cannot be started

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

['bcm2835 Headphones: - (hw:0,0)', 'USB PnP Sound Device: Audio (hw:1,0)', 'vc4-hdmi: MAI PCM i2s-hifi-0 (hw:2,0)', 'sysdefault', 'spdif', 'lavrate', 'samplerate', 'speexrate', 'pulse', 'upmix', 'vdownmix', 'default']

ALSA lib pcm_dmix.c:1075:(snd_pcm_dmix_open) unable to open slave

ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.USB-Audio.pcm.hdmi.0:CARD=1,AES0=4,AES1=130,AES2=0,AES3=2'

ALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory

ALSA lib conf.c:5233:(snd_config_expand) Evaluate error: No such file or directory

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM hdmi

ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.USB-Audio.pcm.hdmi.0:CARD=1,AES0=4,AES1=130,AES2=0,AES3=2'

ALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory

ALSA lib conf.c:5233:(snd_config_expand) Evaluate error: No such file or directory

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM hdmi

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline

Cannot connect to server socket err = No such file or directory

Cannot connect to server request channel

jack server is not running or cannot be started

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

Cannot connect to server socket err = No such file or directory

Cannot connect to server request channel

jack server is not running or cannot be started

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

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:1075:(snd_pcm_dmix_open) unable to open slave

Cannot connect to server socket err = No such file or directory

Cannot connect to server request channel

jack server is not running or cannot be started

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

ALSA lib pcm_dmix.c:1075:(snd_pcm_dmix_open) unable to open slave

ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.USB-Audio.pcm.hdmi.0:CARD=1,AES0=4,AES1=130,AES2=0,AES3=2'

ALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory

ALSA lib conf.c:5233:(snd_config_expand) Evaluate error: No such file or directory

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM hdmi

ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.USB-Audio.pcm.hdmi.0:CARD=1,AES0=4,AES1=130,AES2=0,AES3=2'

ALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory

ALSA lib conf.c:5233:(snd_config_expand) Evaluate error: No such file or directory

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM hdmi

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline

Cannot connect to server socket err = No such file or directory

Cannot connect to server request channel

jack server is not running or cannot be started

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

Cannot connect to server socket err = No such file or directory

Cannot connect to server request channel

jack server is not running or cannot be started

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

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:1075:(snd_pcm_dmix_open) unable to open slave

Cannot connect to server socket err = No such file or directory

Cannot connect to server request channel

jack server is not running or cannot be started

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

 

๊ทธ๋ž˜๋„ ์œ„ ๊ฒฝ๊ณ ๋“ค์ด ๋ณด๊ธฐ ์‹ซ๋‹ค๋ฉด 

python3 main.py 2>/dev/null

๋กœ ์‹คํ–‰์‹œํ‚ค๋ฉด ๊ฒฝ๊ณ ๋“ค์ด ์•ˆ๋ณด์ธ๋‹ค. 

ํ•˜์ง€๋งŒ ์ง„์งœ ๋ด์•ผํ•˜๋Š” ์—๋Ÿฌ๋„ ๋ณด์ด์ง€ ์•Š์œผ๋ฏ€๋กœ ์ฃผ์˜