Is there any option in Python for Record & Play back?

0 votes
If I want to Record an instance, are there any options in Python for Record & Play back?
asked Jul 19 in Python by Prashant

2 Answers

0 votes

https://python-sounddevice.readthedocs.io/en/0.3.8/

Play and Record Sound with Python

answered Jul 19 by anonymous
0 votes

import pyaudio
import wave
import sys

CHUNK = 1024

if len(sys.argv) < 2:
    print("Plays a wave file.\n\nUsage: %s filename.wav" % sys.argv[0])
    sys.exit(-1)

wf = wave.open(sys.argv[1], 'rb')

# instantiate PyAudio (1)
p = pyaudio.PyAudio()

# open stream (2)
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
                channels=wf.getnchannels(),
                rate=wf.getframerate(),
                output=True)

# read data
data = wf.readframes(CHUNK)

# play stream (3)
while len(data) > 0:
    stream.write(data)
    data = wf.readframes(CHUNK)

# stop stream (4)
stream.stop_stream()
stream.close()

# close PyAudio (5)
p.terminate()
answered Jul 19 by anonymous
...