Python Forum
How to do real-time audio signal processing using python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to do real-time audio signal processing using python
#8
The following works. I got it from GitHub https://gist.github.com/mabdrabo/8678538
and modified it to work with Python 3. It will record several seconds from the microphone then saves if off as a .wav file
import pyaudio
import wave
 
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
CHUNK = 1024
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "file.wav"
 
audio = pyaudio.PyAudio()
 
# start Recording
stream = audio.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 ("finished recording")
 
 
# stop Recording
stream.stop_stream()
stream.close()
audio.terminate()
 
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()
Reply


Messages In This Thread
RE: How to do real-time audio signal processing using python - by jefsummers - Nov-04-2019, 02:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  error python audio codiac 3 4,209 Mar-30-2023, 03:12 PM
Last Post: deanhystad
  Non-blocking real-time plotting slow_rider 5 3,699 Jan-07-2023, 09:47 PM
Last Post: woooee
  How to change UTC time to local time in Python DataFrame? SamKnight 2 1,627 Jul-28-2022, 08:23 AM
Last Post: Pedroski55
  python audio analysis kiyoshi7 3 1,792 Feb-22-2022, 06:09 PM
Last Post: Axel_Erfurt
  Real time database satyanarayana 3 1,684 Feb-16-2022, 01:37 PM
Last Post: buran
  Real time data satyanarayana 3 25,058 Feb-16-2022, 07:46 AM
Last Post: satyanarayana
  Real time Detection and Display Gilush 0 1,805 Feb-05-2022, 08:28 PM
Last Post: Gilush
  mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python ilknurg 3 5,665 Jan-18-2022, 06:25 PM
Last Post: ilknurg
  Real-Time output of server script on a client script. throwaway34 2 2,075 Oct-03-2021, 09:37 AM
Last Post: ibreeden
  Why recursive function consumes more of processing time than loops? M83Linux 9 4,294 May-20-2021, 01:52 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020