My goal is to record my voice through the laptop mic and simultaneously adding an effect to it, in python. What I need is similar to a music effects pedal where you connect
To expand on Luke's answer:
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
In your code is where you commit to a certain time of recording. If you wrote a function "isSilent" that can determine if a chunk is silent, your code might change to:
while len(frames) <= 0 or not isSilent(frames[-1]):
data = stream.read(CHUNK)
frames.append(data)
If "isSilent" is to hard to write or if it is to computationally slow you can wait for user input. KeyboardInterrupt is a first hack to play with this method:
try:
while true:
data = stream.read(CHUNK)
frames.append(data)
except KeyboardInterrupt:
pass
This is a hack, and not the right way to look for user input in production, but it will let you start experimenting with this. you will want to find or make a stopButtonHasBeenPressed function.
while not stopButtonHasBeenPressed():
data = stream.read(CHUNK)
frames.append(data)