【问题标题】:ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directoryALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
【发布时间】:2018-04-07 09:23:47
【问题描述】:

我得到一个错误,ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory 。 当我运行这段代码时

#!/usr/bin/env python
from __future__ import division
import re
import sys
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
import pyaudio
from six.moves import queue
# [END import_libraries]

# Audio recording parameters
RATE = 44100
CHUNK = 8192  # 100ms

class MicrophoneStream(object):
    def __init__(self, rate, chunk):
        self._rate = rate
        self._chunk = chunk

        # Create a thread-safe buffer of audio data
        self._buff = queue.Queue()
        self.closed = True

    def __enter__(self):
        self._audio_interface = pyaudio.PyAudio()
        self._audio_stream = self._audio_interface.open(
            format=pyaudio.paInt16,
            channels=1, rate=self._rate,
            input=True, frames_per_buffer=self._chunk,
            stream_callback=self._fill_buffer
        )

        self.closed = False

        return self

    def __exit__(self, type, value, traceback):
        self._audio_stream.stop_stream()
        self._audio_stream.close()
        self.closed = True
        self._buff.put(None)
        self._audio_interface.terminate()

    def _fill_buffer(self, in_data, frame_count, time_info, status_flags):
        self._buff.put(in_data)
        return None, pyaudio.paContinue

    def generator(self):
        while not self.closed:
            chunk = self._buff.get()
            if chunk is None:
                return
            data = [chunk]

            while True:
                try:
                    chunk = self._buff.get(block=False)
                    if chunk is None:
                        return
                    data.append(chunk)
                except queue.Empty:
                    break

            yield b''.join(data)

def listen_print_loop(responses):
    num_chars_printed = 0
    for response in responses:
        if not response.results:
            continue

        result = response.results[0]
        if not result.alternatives:
            continue

        transcript = result.alternatives[0].transcript

        overwrite_chars = ' ' * (num_chars_printed - len(transcript))

        if not result.is_final:
            sys.stdout.write(transcript + overwrite_chars + '\r')
            sys.stdout.flush()

            num_chars_printed = len(transcript)

        else:
            print(transcript + overwrite_chars)

            if re.search(r'\b(exit|quit)\b', transcript, re.I):
                print('Exiting..')
                break

            num_chars_printed = 0


def main():
    language_code = 'en-US'  # a BCP-47 language tag

    client = speech.SpeechClient()
    config = types.RecognitionConfig(
        encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,
        sample_rate_hertz=RATE,
        language_code=language_code)
    streaming_config = types.StreamingRecognitionConfig(
        config=config,
        interim_results=True)

    with MicrophoneStream(RATE, CHUNK) as stream:
        audio_generator = stream.generator()
        requests = (types.StreamingRecognizeRequest(audio_content=content)
                    for content in audio_generator)

        responses = client.streaming_recognize(streaming_config, requests)

        listen_print_loop(responses)


if __name__ == '__main__':
    main()

错误发生

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

我想我已经安装了在 raspberrypi 中播放声音所需的东西。所以我真的不明白为什么会发生这个错误。我更改了 RATE 和 CHUNK 的值,例如 RATE = 8000 或 CHUNK = 1024 *2 等,但发生了同样的错误。如何我可以解决这个问题吗?我没有安装必要的东西来播放声音吗?

【问题讨论】:

    标签: python ubuntu raspberry-pi3


    【解决方案1】:

    我也在树莓派中使用谷歌云语音识别并得到同样的错误。然而,就我而言,尽管有这些错误,语音识别仍然有效。

    我找到了这个答案:PyAudio working, but spits out error messages each time。看来这是 /usr/share/alsa/alsa.conf 文件的问题。我评论了与错误相关的行,错误消息消失了。最初的 aswer 建议不要评论这些行,但这是检查它是否有效的最快方法。

    如果您无法使用 Speech API,您的问题与这些错误消息无关。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-11
      • 2016-05-25
      • 2012-06-03
      • 2013-07-02
      • 2019-07-23
      • 2023-04-03
      • 2018-11-22
      • 2014-01-20
      相关资源
      最近更新 更多