gpt4 book ai didi

Python AlsaLib 错误

转载 作者:行者123 更新时间:2023-12-05 07:39:13 24 4
gpt4 key购买 nike

我想加载一个音频文件并重现它。下面的代码有效,但我在控制台中有很多错误。

import simpleaudio as sa
import wave
import matplotlib.pyplot as plt
import sys
import pyaudio

f = wave.open('file.wav','rb')
p = pyaudio.PyAudio()
#open stream
stream = p.open(format = p.get_format_from_width(f.getsampwidth()),
channels = f.getnchannels(),
rate = f.getframerate(),
output = True)
#read data
data = f.readframes(1024)

#play stream
while data:
stream.write(data)
data = f.readframes(1024)

#stop stream
stream.stop_stream()
stream.close()

#close PyAudio
p.terminate()

我使用此代码通过 python 3 重现波形音频。一切正常,但在控制台中我读到:

ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
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 4294967295, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for 4294967295, skipping unlock

问题是什么?我该如何解决?

最佳答案

3 年后:我没有解决方案,但也许我有一个提示。

import speech_recognition as sr
mic = sr.Microphone(chunk_size=1024)
pi = sr.Recognizer()
with mic as source:
pi.adjust_for_ambient_noise(source)
print("Hear: ")
audio = pi.listen(source, timeout=5, phrase_time_limit=20)
print("Recognize...")
try:
a = pi.recognize_google(audio, language="en-us")
print(a)
except Exception as e:
print(e)

我正在使用 Raspberry-Pi (Linux) Raspbian。此错误消息不是代码问题,它来自模块 PyAudio。但一切正常,所以这不是严重错误。抱歉我的英语不好,我是德国人。

关于Python AlsaLib 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47178739/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com