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:
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
for
other cycles
for
who were the counter