I generaed a beep sound in Python, that exists for 5ms, and repeats after every 1s, for next 10s.
The codes are as such:
## Import modules
import time
import sys
import winsound
import soundfile as sf
## Set frequency and duration of beep sound
frequency = 37
duration = 5 # duration of beep sound is 5ms
for i in range(1,10): # create beep sound for 10s
## Create beep sound for 5 ms, after every 1 s
sys.stdout.write('\r\a{i}'.format(i=i))
sys.stdout.flush()
winsound.Beep(frequency, duration)
time.sleep(1) # Repeat beep sound after 1s
Now, I want to save this pattern in a .wav file. Hence, I changed the codes as such:
## Import modules
import time
import sys
import winsound
import soundfile as sf
## Set frequency and duration of beep sound
frequency = 37
duration = 5 # duration of beep sound is 5ms
for i in range(1,10): # create beep spund for 10 s
## Create beep sound for 5 ms, after every 1 s
sys.stdout.write('\r\a{i}'.format(i=i))
sys.stdout.flush()
winsound.Beep(frequency, duration)
time.sleep(1)
## Save the beep spund as a .wav file
sf.write("Beep.wav", winsound.Beep(frequency, duration))
However, I keep geeting errors.
Can somebady please let me know how do I save this in a .wav file ?
The error is this:
from the docs here: https://pysoundfile.readthedocs.io/en/latest/
we can see that the function requires 3 arguments:
The code in the question has provided only two arguements.
The 3 arguements are:
It
samplerate
is missing.With the docs given, this works: