So i'm triying to make a exercise here that I have to record my voice using pyaudio. I don't know if need a mic or if the code is wrong, but this keeps happenig when run the program:
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:869:(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 -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
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 -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
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 -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Start recording
Traceback (most recent call last):
File "/home/sindri-21/Desktop/Python/teste_audio.py", line 32, in <module>
obj.setchannels(CHANNELS)
AttributeError: 'Wave_write' object has no attribute 'setchannels'
Exception ignored in: <function Wave_write.__del__ at 0x7faf94040dc0>
Traceback (most recent call last):
File "/usr/lib/python3.8/wave.py", line 327, in __del__
File "/usr/lib/python3.8/wave.py", line 445, in close
File "/usr/lib/python3.8/wave.py", line 463, in _ensure_header_written
wave.Error: # channels not specified
Anyway, this is the code:
import pyaudio
import wave
FRAMES_PER_BUFFER = 32000
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 16000
p = pyaudio.PyAudio()
stream = p.open(
format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=FRAMES_PER_BUFFER
)
print("Start recording")
seconds = 5
frames = []
for i in range(0, int(RATE/FRAMES_PER_BUFFER*seconds)):
data = stream.read(FRAMES_PER_BUFFER)
frames.append(data)
stream.stop_stream()
stream.close()
p.terminate()
obj = wave.open("output.wav", "wb")
obj.setchannels(CHANNELS)
obj.setsampwidth(p.get_sample_size(FORMAT))
obj.setframerate(RATE)
obj.writeframes(b"".join(frames))
obj.close()
I just want to know why it doesn't works, maybe the channels, maybe is version of pyaudio (0.2.11), the lack of a mic, etc...