Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_audio_coreader():
if sys.platform.startswith("win"):
pytest.skip("Temporarily skipping on windows because otherwise test suite fails with Invalid Handle Error")
sound = AudioFileClip("media/crunching.mp3")
sound = sound.subclip(1, 4)
sound2 = AudioFileClip("media/crunching.mp3")
sound2.write_audiofile(os.path.join(TMP_DIR, "coreader.mp3"))
def test_normalize():
clip = AudioFileClip('media/crunching.mp3')
clip = audio_normalize(clip)
assert clip.max_volume() == 1
close_all_clips(locals())
def test_audioclip_with_file_concat():
if sys.platform.startswith("win"):
pytest.skip("Temporarily skipping on windows because otherwise test suite fails with Invalid Handle Error")
make_frame_440 = lambda t: [sin(440 * 2 * pi * t)]
clip1 = AudioClip(make_frame_440, duration=1, fps=44100)
clip2 = AudioFileClip("media/crunching.mp3")
concat_clip = concatenate_audioclips((clip1, clip2))
return
# Fails with strange error
# "ValueError: operands could not be broadcast together with
# shapes (1993,2) (1993,1993)1
concat_clip.write_audiofile(os.path.join(TMP_DIR, "concat_clip_with_file_audio.mp3"))
def subclip_list(media_path, range_pairs, out_dir=''):
if out_dir=='':
out_dir = os.path.dirname(media_path)
snd = AudioFileClip.AudioFileClip(media_path)
file_duration = duration(media_path)
for pair in range_pairs:
start = pair[0]
duration_secs = pair[1]
if (float(start) >= 0.0) & (float(duration_secs) > 0.0):
if start + duration_secs > file_duration:
duration_secs = file_duration - start
basename = media_path.split('/')[-1][:-4]
out_filename = basename+'__'+str(round(start, 4))+'_'+str(round(duration_secs ,4))+'.wav'
snd.subclip(float(start),float(start)+float(duration_secs)).write_audiofile(os.path.join(out_dir, out_filename))
def subclip(media_path,start_time,end_time,out_dir=''):
if out_dir=='':
out_dir = os.path.dirname(media_path)
audio_filename=media_path.split('/')[-1]
basename = audio_filename[:-4]
start_time = round(float(start_time),3)
end_time = round(float(end_time),3)
snd = AudioFileClip.AudioFileClip(media_path)
out_filename = basename+'__'+str(start_time)+'_'+str(end_time)+'.wav'
snd.subclip(start_time,end_time).write_audiofile(os.path.join(out_dir,out_filename))
return os.path.join(out_dir,out_filename)
def coreader(self):
""" Returns a copy of the AudioFileClip, i.e. a new entrance point
to the audio file. Use copy when you have different clips
watching the audio file at different times. """
return AudioFileClip(self.filename, self.buffersize)
def _load_clip(self):
self.clip = AudioFileClip(self.filename, fps=self.sampling_rate)
def _load_clip(self):
self.clip = AudioFileClip(self.filename, fps=self.sampling_rate)