Reputation: 191
When I use wavfile.write() with a filename that I previously used but deleted, instead of writing the wav file with the newly recorded audio, it seems to resurrect the deleted file. This happens even if I record in a different directory. For example if I at one point had a file '/Users/folder1/test.wav', deleted this recording and then recorded a new file '/Users/folder2/test.wav', this new recording is of the audio I had deleted. Now, if I just use a new filename entirely there's no problem. Can anyone tell me what's happening?
_, data = record()
wavfile.write('/Users/folder1/test.wav', RATE, data)
def record():
"""
Record a word or words from the microphone and
return the data as an array of signed shorts.
Normalizes the audio, trims silence from the
start and end, and pads with 0.5 seconds of
blank sound to make sure VLC et al can play
it without getting chopped off.
"""
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT, channels=1, rate=RATE,
input=True, output=True,
frames_per_buffer=CHUNK_SIZE)
num_silent = 0
snd_started = False
r = array('h')
while 1:
# little endian, signed short
snd_data = array('h', stream.read(CHUNK_SIZE))
if byteorder == 'big':
snd_data.byteswap()
r.extend(snd_data)
silent = is_silent(snd_data)
if silent and snd_started:
num_silent += 1
elif not silent and not snd_started:
snd_started = True
if snd_started and num_silent > 30:
break
sample_width = p.get_sample_size(FORMAT)
stream.stop_stream()
stream.close()
p.terminate()
r = normalize(r)
r = trim(r)
r = add_silence(r, 0.5)
return sample_width, np.asarray(r)
Upvotes: 0
Views: 515
Reputation: 191
I am a fool... The problem was with iTunes, not with the code. Thanks to everyone who looked at this.
Upvotes: 1