La guía paso a paso o código que hallarás en este artículo es la solución más sencilla y efectiva que hallamos a esta duda o dilema.
Ejemplo: grabar y almacenar audio en pythn
import pyaudio
import wave
chunk =1024# Record in chunks of 1024 samples
sample_format = pyaudio.paInt16 # 16 bits per sample
channels =2
fs =44100# Record at 44100 samples per second
seconds =3
filename ="output.wav"
p = pyaudio.PyAudio()# Create an interface to PortAudioprint('Recording')
stream = p.open(format=sample_format,
channels=channels,
rate=fs,
frames_per_buffer=chunk,input=True)
frames =[]# Initialize array to store frames# Store data in chunks for 3 secondsfor i inrange(0,int(fs / chunk * seconds)):
data = stream.read(chunk)
frames.append(data)# Stop and close the stream
stream.stop_stream()
stream.close()# Terminate the PortAudio interface
p.terminate()print('Finished recording')# Save the recorded data as a WAV file
wf = wave.open(filename,'wb')
wf.setnchannels(channels)
wf.setsampwidth(p.get_sample_size(sample_format))
wf.setframerate(fs)
wf.writeframes(b''.join(frames))
wf.close()
Puntuaciones y reseñas
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)