audio.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:high-quality-chat 作者: b6938236 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号