data_preprocessing.py 文件源码

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

项目:AVSR-Deep-Speech 作者: pandeydivesh15 项目源码 文件源码
def split(split_file_path, main_file_path, transcript_path, split_info):
    '''
    Here, splitting takes place.

    Args:
        split_file_path:    File path for new split file.
        main_file_path:     File path for original .wav file.
        transcript_path:    File path where transcript will be written.
        split_info:         A tuple of the form (x, (y, z))
    '''
    audio_file = wave.open(main_file_path, 'rb')
    split_file = wave.open(split_file_path, 'wb')

    t0, t1 = split_info[1] # cut audio between t0, t1 seconds
    s0, s1 = int(t0*audio_file.getframerate()), int(t1*audio_file.getframerate())

    audio_file.readframes(s0) # discard frames up to s0
    frames = audio_file.readframes(s1-s0)

    split_file.setparams(audio_file.getparams())
    split_file.writeframes(frames)
    split_file.close()

    # Store transcript
    with open(transcript_path, 'wb') as f:
        f.write(split_info[0])

    # TODO: Get rid of multiple opening and closing of the same main audio file.
    audio_file.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号