B06.有意思的小东西 -切分音频mp3,过滤不感兴趣的部分

本文介绍了如何使用ffmpeg工具和python的pydub库来切分mp3音频,重点讲述了如何通过ffmpeg解决切分特定音频时遇到的问题,最终成功切分并过滤掉不感兴趣的部分。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、获取音频

先用https://github.com/zeakhold/xmlyfetcher下载音频。

npm install -g xmlyfetcher

二、切分音频一般方法

1,利用python pydub库切割mp3 https://blog.youkuaiyun.com/u014633966/article/details/85244347

pip install pydub

并安装ffmpeg
代码:

from pydub import AudioSegment

tmp = "aaa.mp3"
audio = AudioSegment.from_mp3(tmp)
audio[35*1000:45*1000].export("out.mp3", format="mp3")
print("finish")

对于mp3音乐,可行。
对于我的音频,不可行,报错如下。

Traceback (most recent call last):
  File ".\zjl周杰伦的可以切1.py", line 19, in <module>
    audio = AudioSegment.from_mp3(tmp)
  File "C:\Users\ASUS\Anaconda3\lib\site-packages\pydub\audio_segment.py", line 716, in from_mp3
    return cls.from_file(file, 'mp3', parameters=parameters)
  File "C:\Users\ASUS\Anaconda3\lib\site-packages\pydub\audio_segment.py", line 704, in from_file
    p.returncode, p_err))
pydub.exceptions.CouldntDecodeError: Decoding failed. ffmpeg returned error code: 1

Output from ffmpeg/avlib:

b"ffmpeg version git-2019-12-10-e73688e Copyright (c) 2000-2019 the FFmpeg developers\r\n  built with gcc 9.2.1 (GCC) 20191125\r\n  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值