Hello,
I am able to install the pyaudio packages as mentioned in the below link.
Now I would like to run some python example to play & record audio.
I have connected the USB audio card to record the voice.
"""PyAudio example: Record a few seconds of audio and save to a WAVE file."""
import pyaudio
import wave
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("* recording")
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
print("* done recording")
stream.stop_stream()
stream.close()
p.terminate()
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
Tried the above example and got the below error.
root@apalis-imx6:/test_pyaudio# python test_arecord.py
Traceback (most recent call last):
File "test_arecord.py", line 20, in <module>
frames_per_buffer=CHUNK)
File "/usr/lib/python2.7/site-packages/pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/pyaudio.py", line 441, in __init__
self._stream = pa.open(**arguments)
IOError: [Errno -9996] Invalid input device (no default output device)
root@apalis-imx6:/test_pyaudio#
BTW, I am able to record using ‘arecord’ command.
root@apalis-imx6:/test_pyaudio#
root@apalis-imx6:/test_pyaudio# arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: U0x46d0x81b [USB Device 0x46d:0x81b], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
root@apalis-imx6:/test_pyaudio#
root@apalis-imx6:/test_pyaudio#
root@apalis-imx6:/test_pyaudio# arecord -f CD test2.wav
Recording WAVE 'test2.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
^CAborted by signal Interrupt...
arecord: pcm_read:2096: read error: Interrupted system call
root@apalis-imx6:/test_pyaudio#
root@apalis-imx6:/test_pyaudio#
get_device_count() returns 0.
(env) root@apalis-imx6:/#
(env) root@apalis-imx6:/# python
Python 2.7.12 (default, Jul 13 2017, 04:51:34)
[GCC 6.2.1 20161016] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import pyaudio
>>> pa = pyaudio.PyAudio()
>>> pa.get_device_count()
0L
>>> pa.get_default_input_device_info()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/env/lib/python2.7/site-packages/pyaudio.py", line 949, in get_default_input_device_in
fo
device_index = pa.get_default_input_device()
IOError: No Default Input Device Available
>>>
Can you please help me on this issue ?
Thanks for the help.