pythonpython-3.xscipypython-sounddevice

When recording on python with module sounddevice it records forever


I am currently making a python script that records for a specific amount of time that the user inputs, and then encrypts it with a password.

But when I start recording, it records forever, and I have to stop the script running to stop recording.

from sounddevice import rec, wait
from scipy.io.wavfile import write
from getpass import getpass
from pyAesCrypt import encryptFile
from os import remove

fs = 44100  # Sample rate
while True:
    try:
        seconds = int(input("Enter how long to record for: "))
    except ValueError:
        print("Must be an integer!")
    else:
        break
myrecording = rec(int(seconds * fs), samplerate=fs, channels=2)  # Record file
wait()  # Wait until recording is finished
write('output.wav', fs, myrecording)
password = getpass("Enter password to encrypt file with: ")
encryptFile("output.wav", "output.ewf", password)
remove("output.wav")
print("Saved file as output.ewf")

is my code.

I have no idea why it stopped working. Thanks


Solution

  • For the googlers out there, don't worry, it's fixed.

    If you use PyCharm, then make sure to edit configuration and check Emulate terminal in output console

    I think the problem was getpass.