代码之家  ›  专栏  ›  技术社区  ›  qwerty

连接音频文件[Python 2.7]

  •  0
  • qwerty  · 技术社区  · 9 年前

    有什么方法可以将两个音频文件连接或合并为一个?

    要求 :只能使用内置模块[可以使用PyGame]

    音频文件格式 :.wma或.wav或.mp3

    我现在已经研究了很多问题,并找到了涉及下载模块的解决方案(我不喜欢)。

    欢迎任何帮助。

    2 回复  |  直到 9 年前
        1
  •  2
  •   Community CDub    8 年前

    我做了一些研究,发现了这个。

    #import libraries
    from glob import iglob
    import shutil
    import os
    #create path variable
    PATH = r'C:\music'
    #create everything.mp3
    destination = open('everything.mp3', 'wb')
    for filename in iglob(os.path.join(PATH, '*.mp3')):
        shutil.copyfileobj(open(filename, 'rb'), destination)
    #make them all together with for
    destination.close()
    #close file
    

    从…起 here .

        2
  •  0
  •   rearThing    9 年前

    事实上,只要两个文件由同一编码器生成,我就可以通过连接来连接两个Flac文件:

    audio1 = open("audio1.flac", "rb").read()
    audio2 = open("audio2.flac", "rb").read()
    audioJoin = audio1 + audio2
    audioFinal = open("audioFinal.flac", "wb").write(audioJoin)