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

问题描述 投票:0回答:2

我得到一个错误,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
2个回答
1
投票

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

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

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


0
投票

对于使用 SpeechRecognition python 库在树莓派上遇到此错误的任何人,为我修复它的是确保我指定了正确的设备索引,例如

sr.Microphone(device_index=2)
您可以通过运行
aplay -l

查看您拥有的设备及其索引
© www.soinside.com 2019 - 2024. All rights reserved.