简体   繁体   English

将.aiff音频文件转换为.wav

[英]Converting .aiff audio file to .wav

I'm trying to convert some audio files using a python script. 我正在尝试使用python脚本转换一些音频文件。 The source folder contains both .wav and .aiff audio files, with different bitrates and sampling rates. 源文件夹包含.wav.aiff音频文件,具有不同的比特率和采样率。

INPUT Files example 输入文件示例

在此处输入图片说明

I need all the audio files to be converted to mono 16bit 44.1khz .wav 我需要将所有音频文件转换为单声道16位44.1khz .wav

OUTPUT Files example 输出文件示例

在此处输入图片说明

At the moment I'm succesfully using pysoundfile library to open and write/convert .wav files to PCM_16 type. 目前,我成功地使用pysoundfile库打开并将.wav文件写入/转换为PCM_16类型。

What I don't know how to do, is converting .aiff files to .wav ones. 我不知道该怎么办,是将.aiff文件转换为.wav文件。

I know Python handles .aiff files with the aifc library, but it doesn't seems to include any kind of conversion functionality. 我知道Python使用aifc库处理.aiff文件,但是它似乎不包含任何类型的转换功能。

How can I do that? 我怎样才能做到这一点?

Disclaimer: Probably this is not the answer you're looking for, because it is not "Python-only"; 免责声明:可能这不是您要查找的答案,因为它不是“仅Python”。 however, when I tried to work with media files in a large Python script I found this method easier than searching and reading documentation of a bunch of libraries for each media format I needed. 但是,当我尝试使用大型Python脚本处理媒体文件时,我发现此方法比为我需要的每种媒体格式搜索和阅读一堆库的文档要容易。

Install a media converter (fe, I use FFmpeg ), whose commands you can execute from Windows command line or Linux terminal. 安装一个媒体转换器(例如,我使用FFmpeg ),您可以从Windows命令行或Linux终端执行其命令。 Then you can call these commands from a Python script: 然后,您可以从Python脚本调用以下命令:

from subprocess import call 
call('ffmpeg -i D:/Audio/IN/sample.aiff -acodec pcm_s16le -ac 1 -ar 44100 D:/Audio/OUT/sample.wav')

(Here '-ac 1' means 1 audio track, that is, we convert to mono.) You can also extract audio from any video format in a similar way. (这里的“ -ac 1”表示1个音轨,即我们转换为单声道。)您还可以类似的方式从任何视频格式中提取音频。

This is a non-issue. 这不是问题。 The soundfile module you are already using does support AIFF files out-of-the-box. 您已经在使用的soundfile模块确实支持AIFF文件。 Just specify the file name and you are done! 只要指定文件名,您就完成了!

You can use the function soundfile.available_formats() to get a list of supported formats. 您可以使用函数soundfile.available_formats()来获取受支持格式的列表。 The soundfile module uses the libsndfile library under the hood. soundfile模块在libsndfile使用libsndfile库。 There is a list of supported formats on their homepage (which contains AIFF). 它们的主页上有支持的格式列表 (包含AIFF)。

Like @Wolfram mentioned, you can of course also use FFmpeg instead. 就像提到的@Wolfram一样,您当然也可以使用FFmpeg代替。 Another great external tool for audio conversion is SoX . SoX是另一个用于音频转换的出色外部工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM