当前位置:网站首页>Splicing audio files with ffmpeg-4.3
Splicing audio files with ffmpeg-4.3
2022-06-24 21:03:00 【CrazyManhhh】
from scipy.io import wavfile
import numpy as np
from os import listdir
from ffmpy import FFmpeg as mpy
import os
import shutil
class ConbineSound(object):
"""docstring for ConbineSound"""
def __init__(self,saveName):
super(ConbineSound, self).__init__()
#mp3 convert to wav Format Directory , That is, the directory of audio splicing
self.wavPath = r'C:\Users\HK\Desktop\ speech recognition \wav'
#mp3 Initial file directory
self.mp3Path = r'C:\Users\HK\Desktop\ speech recognition \sound2'
# The final synthesized audio file
# self.saveName = r'C:\Users\HK\Desktop\python\ The code base \ Online character recognition \static\media\result_sound.mp3'
self.saveName = saveName
def combineS(self):
wavs = listdir(self.wavPath)
wavs = sorted(wavs,key=lambda x:int(x.split('.')[0]))
all_sounds = []
for wav in wavs:
file = self.wavPath + '/' + wav
data = wavfile.read(file)
all_sounds.append(data[1][:10 * 14100])
mix = np.concatenate(all_sounds)
wavfile.write(self.saveName, 14100, mix)
# Empty folder
def delFiles(self):
# 2. Delete folder
shutil.rmtree(self.wavPath)
# 3. Recreate the folder
os.mkdir(self.wavPath)
def trans_to_wav(self,mp3_file, wav_folder):
'''
Format conversion
:param mp3_file:
:param wav_folder:
:return:
'''
# Format file
file_fmt = os.path.basename(mp3_file).strip()
# Get file format
file_fmt = file_fmt.split('.')[-1]
# Verify file format
if file_fmt.strip() != 'mp3':
raise Exception(' Change file is not MP3 Format , Please check !')
elif file_fmt.strip() == '':
raise Exception(' Exception in file format , Please check !')
# establish wav For output after conversion
wav_file_path = os.path.join(wav_folder)
wav_file_path = os.path.join(wav_file_path, '{}.{}'.format(
os.path.basename(mp3_file).strip().split('.')[0], 'wav'
))
# Command line parameter string when creating conversion
cmder = '-f wav -ac 1 -ar 16000'
# Create converter object
mpy_obj = mpy(
inputs={
mp3_file: None
},
outputs={
wav_file_path: cmder
}
)
print(' perform CMDER command :{}'.format(mpy_obj.cmd))
mpy_obj.run()
def read_folder(self):
'''
Folder read function
:param mp3_folder:
:param wav_folder:
:return:
'''
# Traversing the... That needs to be converted MP3 In folder MP3 file
mp3_folder = self.mp3Path
wav_folder = self.wavPath
for a in os.listdir(mp3_folder):
# establish MP3 The absolute path to the file
mp3_file = os.path.join(mp3_folder, a)
# Call the format conversion function
self.trans_to_wav(mp3_file, wav_folder)function : Will one mp3 Files are converted in batch to wav Format , And then wav The format depends on the file name ( for example :1.wav,2.wav) Sort and splice .
install : be used ffmpeg-4.3-win64-static Software , After installation D:\ffmpeg-4.3-win64-static\bin Add to environment variables , then pip install ffmpeg==1.4 ;scipy It's best to use it. 1.2.1
边栏推荐
- A/b test helps the growth of game business
- Packaging_ Conversion between basic type and string type
- 2021-09-30
- The four stages of cloud computing development have finally been clarified
- Background operation retry gave up; KeeperErrorCode = ConnectionLoss
- 海泰前沿技术|隐私计算技术在医疗数据保护中的应用
- It was Tencent who jumped out of the job with 26k. It really wiped my ass with sandpaper. It gave me a hand
- After 5 months' test, it took 15K to come for an interview. When I asked, it was not worth even 5K. It was really
- "Super point" in "Meng Hua Lu", is the goose wronged?
- Berkeley, MIT, Cambridge, deepmind et d'autres grandes conférences en ligne: vers une IA sûre, fiable et contrôlable
猜你喜欢

A/b test helps the growth of game business
![Use the transparent [x] cross button image in the dialog](/img/0c/2be7bc7f20b581a2cc745d9cabe9ff.jpg)
Use the transparent [x] cross button image in the dialog
浅谈MySql update会锁定哪些范围的数据

maptalks:数据归一化处理与分层设色图层加载

Leetcode(135)——分发糖果

伯克利、MIT、剑桥、DeepMind等业内大佬线上讲座:迈向安全可靠可控的AI

Sequence stack version 1.0

海泰前沿技术|隐私计算技术在医疗数据保护中的应用

Interpreter mode -- formulas for dating

Haitai Advanced Technology | application of privacy computing technology in medical data protection
随机推荐
Does the developer want to change to software testing?
Several common command operations in win system
微信小程序自定义tabBar
顺序栈1.0版本
Visitor model -- generation gap between young and middle-aged people
When querying the database with Gorm, reflect: reflect flag. mustBeAssignable using unaddressable value
Combination mode -- stock speculation has been cut into leeks? Come and try this investment strategy!
yeb_ Back first day
Can the OPDS SQL component pass process parameters to the next component through context
Talking about the range of data that MySQL update will lock
得物多活架构设计之路由服务设计
Batch capitalization of MySQL table names
Jd.com: how does redis implement inventory deduction? How to prevent oversold?
JUnit unit test
Simulation lottery and probability statistics experiment of the top 16 Champions League
Coinbase will launch the first encryption derivative for individual investors
Sequence stack version 1.0
Haitai Advanced Technology | application of privacy computing technology in medical data protection
Leetcode (135) - distribute candy
顺序表的基本操作