Spaces:
Runtime error
Runtime error
| import numpy as np | |
| import sounddevice as sd | |
| from scipy.io.wavfile import write | |
| def run(fs=44100, seconds=3, out_filename="output.wav", ask_first=True): | |
| if ask_first: | |
| input("Press Enter to start recording:") | |
| print(f"Recording for {seconds}s...", end=" ") | |
| myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2) | |
| sd.wait() # Wait until recording is finished | |
| print("Finished") | |
| myrecording = np.iinfo(np.int16).max * \ | |
| (myrecording/np.abs(myrecording).max()) | |
| write(out_filename, fs, myrecording.astype(np.int16)) # Save as WAV file | |
| if __name__ == "__main__": | |
| run() | |