简体   繁体   English

如何在python中将asf文件转换为wav或mp3?

[英]How to convert asf file to wav or mp3 in python?

I have an asf file and i want to edit this file using pydub library but its not support asf file Is it possible to convert asf file to wav or mp3 in python?我有一个 asf 文件,我想使用 pydub 库编辑这个文件,但它不支持 asf 文件是否可以在 python 中将 asf 文件转换为 wav 或 mp3? What library that i need to use?我需要使用什么库?

I would like ffmpeg, it is easy and powerful.我想要 ffmpeg,它既简单又强大。 Please look at this link example: ffmpeg -i input.wav -ar 44100 -ac 2 -b:a 192k output.mp3请看这个链接示例:ffmpeg -i input.wav -ar 44100 -ac 2 -b:a 192k output.mp3

-i - input file -i - 输入文件

-ar - Set the audio sampling frequency. -ar - 设置音频采样频率。 For output streams it is set by default to the frequency of the corresponding input stream.对于输出流,它默认设置为相应输入流的频率。 For input streams this option only makes sense for audio grabbing devices and raw demuxers and is mapped to the corresponding demuxer options.对于输入流,此选项仅对音频抓取设备和原始解复用器有意义,并映射到相应的解复用器选项。

-ac - Set the number of audio channels. -ac - 设置音频通道数。 For output streams it is set by default to the number of input audio channels.对于输出流,它默认设置为输入音频通道的数量。 For input streams this option only makes sense for audio grabbing devices and raw demuxers and is mapped to the corresponding demuxer options.对于输入流,此选项仅对音频抓取设备和原始解复用器有意义,并映射到相应的解复用器选项。 So used here to make sure it is stereo (2 channels)所以在这里使用以确保它是立体声(2通道)

-b:a - Converts the audio bitrate to be exact 192kbit per second -b:a - 将音频比特率转换为精确的每秒 192kbit

The python way of using pydub.使用pydub的python方式。 1. Install pydub with pip install pydub and then save a file with this code 2. python code sample: 1. 使用 pip install pydub 安装 pydub,然后使用此代码保存文件 2. python 代码示例:

from pydub import AudioSegment
sound = AudioSegment.from_wav('input.wav')

sound.export('output.mp3', format='mp3')

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

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