Go Down

Topic: Acquire audio and send UDP acquisition parts (Read 146 times) previous topic - next topic

alessandro87gatto

Hello, I hope the session is right.
I need to acquire a sound through a USB microphone, capture the sound for 5 seconds and save the hex stream in a vector. At the end of the 3 seconds, filling a new carrier for another 5 seconds, during this acquisition, the previous carrier will be shot in UDP to the server that will save this information.
The cycle should continue for a total time of 10 minutes.

The python that captures the audio is:

Code: [Select]

import pyaudio
import wave

form_1 = pyaudio.paInt16
chans = 1
samp_rate = 44100
chunk = 4096
record_secs = 10
dev_index = 2
wav_output_filename = 'test.wav'

file = open("test.txt","wb")


audio = pyaudio.PyAudio()

stream = audio.open(format = form_1, rate = samp_rate, channels = chans, \
     input_device_index = dev_index, input = True, \
     frames_per_buffer=chunk)

print("recording")

frames = []

for ii in range(0,int((samp_rate/chunk)*(record_secs/10))):
data = stream.read(chunk)
print(data, "\n")
frames.append(data)


file.write(data)
print("finished recording")

stream.stop_stream()
stream.close()
audio.terminate()

wavefile = wave.open(wav_output_filename,'wb')
wavefile.setnchannels(chans)
wavefile.setsampwidth(audio.get_sample_size(form_1))
wavefile.setframerate(samp_rate)
wavefile.writeframes(b''.join(frames))
wavefile.close()
file.close()


I thought of nesting inside the sky
Quote
for
other cycles
Quote
for
who were the counter

PaulS

Quote
I need to acquire a sound through a USB microphone, capture the sound for 5 seconds and save the hex stream in a vector.
You can completely forget doing this exactly as stated.

You will NOT be using a collector that can change size.

So, you need to start with defining a collector, usually an array, of the maximum size needed. What IS that maximum size, and what type should the collector be, and does your Arduino have enough room to have two of them?

You seem to think that you will be able to send a UDP packet containing all that data, in the time between two samples, so you don't miss a sample. Do you REALLY believe that that is possible? I certainly do not.
The art of getting good answers lies in asking good questions.

Go Up