3

I would like to load an audio file and reproduce it. The following code works, but I have a lot of errors in the console.

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()

I use this code to reproduce a wave audio, with python 3. Everything works, but in the console I read this:

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

What is the problem? How can I fix it?

Camilla8
  • 161
  • 5
  • 16
  • Possible duplicate of [PyAudio working, but spits out error messages each time](https://stackoverflow.com/questions/7088672/pyaudio-working-but-spits-out-error-messages-each-time) – CL. Nov 08 '17 at 13:00

1 Answers1

0

After 3 Years: I don't have a solution, but maybe I have a tip.

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)

I'm using Raspberry-Pi (Linux) Raspbian. This Error Message is no Problem for Code and it comes from the module PyAudio. But all works fine, so it isn't an critical Error. Sorry for my bad English, I'm german.