def _playback(filename, start, end=None, playback_time=None):
"""
Plays back a wav file from the start point (in seconds) to the end point (in seconds)
:param filename: filename to playback
:param start: start time, in seconds. No more than 3 places after decimal or loss of precision
:param end: end time, in seconds. Same as above
:param playback_time: time to play back. use instead of end
"""
file_name, file_extension = os.path.splitext(filename)
# This method will play back filetypes whose extension matches the coded
# This includes wav and mp3 so we should be good
audio = AudioSegment.from_file(filename, format=file_extension[1:])
if end is None and playback_time is not None:
# Play the track starting from start for playback_time seconds
segment = audio[int(start):int(start + playback_time)]
play(segment)
elif end is not None and playback_time is None:
# Play the track starting from start and ending at end
segment = audio[int(start):int(end)]
play(segment)
else:
# Play the whole thing
play(audio)
评论列表
文章目录