карманный сфинкс не может прочитать микрофон - PullRequest
0 голосов
/ 12 декабря 2018

Я пытаюсь прочитать данные с микрофона веб-камеры, подключенного через USB-порт к Raspberry Pi3.Я хочу показать, что мы говорим через микрофон.Но это отправка ошибок.И я установил alsasound в соответствии с этим " библиотека alsaaudio не работает ".Готово Evry правильно, но все равно Ошибка и не считывается с микрофона.

Вот мой код

import os
import threading
import tempfile
tmp_path = os.path.join(tempfile.mkdtemp(prefix='AlexaPi-runtime-'), '')
import alsaaudio
import logging
import platform
from capture import *
import yaml
import config

from pocketsphinx import get_model_path
from pocketsphinx.pocketsphinx import Decoder
config_exists = config.filename is not None

if config_exists:
    with open(config.filename, 'r') as stream:
        config = yaml.load(stream)

##import alexapi.triggers as triggers
##from .basetrigger import BaseTrigger

logger = logging.getLogger(__name__)


class PocketsphinxTrigger():#BaseTrigger

##  type = triggers.TYPES.VOICE

    AUDIO_CHUNK_SIZE = 1024
    AUDIO_RATE = 16000

    _capture = None

    def __init__(self,config,capture): #trigger_callback
##      super(PocketsphinxTrigger, self).__init__(config, 'pocketsphinx') # trigger_callback,

        self._capture = capture

        self._enabled_lock = threading.Event()
        self._disabled_sync_lock = threading.Event()
        self._decoder = None

    def setup(self):
        # PocketSphinx configuration
        ps_config = Decoder.default_config()

        # Set recognition model to US
        ps_config.set_string('-hmm', os.path.join(get_model_path(), 'en-us'))
        ps_config.set_string('-dict', os.path.join(get_model_path(), 'cmudict-en-us.dict'))

        # Specify recognition key phrase
        ps_config.set_string('-keyphrase', self._tconfig['go'])
##      ps_config.set_float('-kws_threshold', float(self._tconfig['threshold']))

        # Hide the VERY verbose logging information when not in debug
##      if logging.getLogger('alexapi').getEffectiveLevel() != logging.DEBUG:
##
##          null_path = '/dev/null'
##          if platform.system() == 'Windows':
##              null_path = 'nul'
##
##          ps_config.set_string('-logfn', null_path)

        # Process audio chunk by chunk. On keyword detected perform action and restart search
        self._decoder = Decoder(ps_config)

    def run(self):
        thread = threading.Thread(target=self.thread, args=())
        thread.setDaemon(True)
        thread.start()

    def thread(self):
        while True:
                        self._enabled_lock.wait()

        ##          self._capture.handle_init(self.AUDIO_RATE, self.AUDIO_CHUNK_SIZE)
                        inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE,alsaaudio.PCM_NORMAL,self._config['sound']['input_device'])
                        inp.setchannels(1)
                        inp.setrate(16000)
                        inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
                        inp.setperiodsize(1024)
                        self._decoder.start_utt()

                        triggered = False
                        while not triggered:
                                if not self._enabled_lock.isSet():
                                        break

                                # Read from microphone
        ##              data = self._capture.handle_read()
                                data = inp.read()
                                # Detect if keyword/trigger word was said
                                self._decoder.process_raw(data, False, False)

                                triggered = self._decoder.hyp() is not None

##          self._capture.handle_release()
                        inp.close()
                        self._decoder.end_utt()

                        self._disabled_sync_lock.set()

##          if triggered:
##              self._trigger_callback(self)

    def enable(self):
        self._enabled_lock.set()
        self._disabled_sync_lock.clear()

    def disable(self):
        self._enabled_lock.clear()
        self._disabled_sync_lock.wait()

if __name__ == '__main__':
        test1_obj = Capture(config,tmp_path)
        test_obj = PocketsphinxTrigger(config,test1_obj)
        test_obj.run()

Это ошибка для вышеуказанного кода

<class 'Exception'>
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.front.0:CARD=0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM front
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 confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround51.0:CARD=0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround21
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround51.0:CARD=0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround21
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround40.0:CARD=0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround40
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround51.0:CARD=0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround41
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround51.0:CARD=0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround50
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround51.0:CARD=0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround51
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.surround71.0:CARD=0'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM surround71
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM iec958
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM spdif
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_alsa.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM spdif
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
connect(2) call to /tmp/jack-0/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
['iBall Face2Face CHD20.0 Webcam: USB Audio (plughw:1,0)', 'mic', 'default']

Этот код предназначен для запуска и запуска. И вот еще один код файла, который не запускается и не читается:

from pocketsphinx import LiveSpeech
for phrase in LiveSpeech(): print(phrase)

Эта ошибка вышеуказанного кода

<class 'pocketsphinx.LiveSpeech'>
Error opening audio device (null) for capture: Connection refused
Traceback (most recent call last):
  File "main.py", line 4, in <module>
    for phrase in LiveSpeech():
  File "/usr/local/lib/python3.5/dist-packages/pocketsphinx/__init__.py", line 206, in __init__
    self.ad = Ad(self.audio_device, self.sampling_rate)
  File "/usr/local/lib/python3.5/dist-packages/sphinxbase/ad_pulse.py", line 124, in __init__
    this = _ad_pulse.new_Ad(audio_device, sampling_rate)
RuntimeError: new_Ad returned -1

Пожалуйста, будьте проще.Заранее спасибо. Любой, пожалуйста, помогите мне.

...