Python3 OSError: [Errno -9988] Поток закрыт - PullRequest
0 голосов
/ 09 июня 2018

Я работаю над системой распознавания голоса с Raspberry pi 3B , и во время выполнения некоторого кода я сталкиваюсь с некоторой проблемой, которая описана ниже.Я перепробовал столько вещей из интернета, но не смог найти какую-то конкретную проблему, поэтому, пожалуйста, помогите мне с ошибкой ниже!

ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4996:(snd_config_expand) Args evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM bluealsa
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4996:(snd_config_expand) Args evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM bluealsa
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.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4996:(snd_config_expand) Args evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM bluealsa
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4996:(snd_config_expand) Args evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM bluealsa
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
Say Somrthing For Google Search
Traceback (most recent call last):
  File "openBrowser.py", line 18, in <module>
    audio = r.listen(source)
  File "/home/pi/Desktop/voiceModule/speech_recognition/__init__.py", line 657, in listen
    buffer = source.stream.read(source.CHUNK)
  File "/home/pi/Desktop/voiceModule/speech_recognition/__init__.py", line 198, in read
    return self.pyaudio_stream.read(size, exception_on_overflow=False)
  File "/usr/lib/python3/dist-packages/pyaudio.py", line 608, in read
    return pa.read_stream(self._stream, num_frames, exception_on_overflow)
OSError: [Errno -9988] Stream closed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "openBrowser.py", line 19, in <module>
    except exception_on_overflow as e:
NameError: name 'exception_on_overflow' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "openBrowser.py", line 21, in <module>
    print('Now, Processing on your request!')
  File "/home/pi/Desktop/voiceModule/speech_recognition/__init__.py", line 188, in __exit__
    self.stream.close()
  File "/home/pi/Desktop/voiceModule/speech_recognition/__init__.py", line 203, in close
    if not self.pyaudio_stream.is_stopped():
  File "/usr/lib/python3/dist-packages/pyaudio.py", line 543, in is_stopped
    return pa.is_stream_stopped(self._stream)
OSError: [Errno -9988] Stream closed

Я сталкиваюсь с ошибкой выше при выполнении кода ниже .py в Raspberry pi :

import speech_recognition as sr
import textToVoice as tv

r = sr.Recognizer()

with sr.Microphone(device_index = 0, sample_rate = 44100, chunk_size = 512) as source:
    print('Say Somrthing For Google Search')
    try:
        audio = r.listen(source)
    except exception_on_overflow as e:
        print('prob')
    print('Now, Processing on your request!')

try:
    text =r.recognize_google(audio)
    lang = 'en'
    tv.tts(text, lang)
    print('You Say:\n' + text)

except Exception as e:
    print('problem For Fatchning Page')
    print(e)

1 Ответ

0 голосов
/ 09 июня 2018

[Errno -9998] Неверное количество каналов

Я улучшаю / очищаю ваш код:

import speech_recognition as sr
import textToVoice as tv

r = sr.Recognizer()

with sr.Microphone() as source:  # your problem was at this line.
    print('Say Something For Google Search')
    try:
        audio = r.listen(source)
    except Exception as e:
        print(e)
    print('Now, Processing on your request!')

try:
    text =r.recognize_google(audio)
    lang = 'en'
    tv.tts(text, lang)
    print('You Say:\n' + text)

except Exception as e:
    print('problem For Fatchning Page')
    print(e)

Для установки выполните следующие шаги:

sudo pip install SpeechRecognition

sudo pip install pyaudio

Если вы нашли ошибку:

sudo apt-get install python-pyaudio

sudo apt-get install libjack-jackd2-dev portaudio19-dev

Затем еще раз:

sudo pip install pyaudio

Если вы обнаружили ошибку, попробуйте следующее:

sudo pip install --upgrade pyaudio

ПРИМЕЧАНИЕ :
Может быть, эта ссылка поможет вам:
https://stackoverflow.com/a/48460182/3702377

...