USB_Audio
ksclark opened this issue · 1 comments
Hello,
I know this may have been slightly covered in another thread, but I wanted to ask for assistance using the USB_Audio.ino connected through USB to a raspberry pi.
I am running a python script to attempt to capture the audio data and save to a wave file. Howver all I get is a bunch of garbled noise.
I have two mini pro's, and I have verified that they are communicating over the radio correctly.
In my python code , I am doing a serial read and I get data like this
I then use the python WAVE module to write those frames to a file
import serial, time
import pyaudio
import wave
import time
timeout = time.time() + 10
FORMAT = pyaudio.paInt8
CHANNELS = 1
RATE = 24000
WAVE_OUTPUT_FILENAME = "file.wav"
audio = pyaudio.PyAudio()
ser = serial.Serial(port='/dev/ttyUSB0', baudrate=115200,
parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS, timeout=0.5)
frames = []
while 1:
print "recording..."
serial_line = ser.read(1)
if time.time() > timeout:
break
frames.append(serial_line)
waveFile = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
waveFile.setnchannels(CHANNELS)
waveFile.setsampwidth(audio.get_sample_size(FORMAT))
waveFile.setframerate(RATE)
waveFile.writeframes(b''.join(frames))
waveFile.close()
ser.close()
print(frames)
exit()
However when I play the wave file I get this
https://www.dropbox.com/s/tfeycxces815nyo/file.wav?dl=0
Any ideas or tips that may point me in the right direction?
I would suggest starting with a low sample rate like 8khz, because there is a lot of overhead in using serial. If the data is being transmitted correctly, I would assume something like that to be the issue. You can try using a faster baud rate if possible also.