当前位置:网站首页>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
边栏推荐
- Steps of JMeter performance test
- Nifi quick installation (stand-alone / cluster)
- yeb_ Back first day
- "Ningwang" was sold and bought at the same time, and Hillhouse capital has cashed in billions by "selling high and absorbing low"
- Open programmable infrastructure (OPI) project, redefining dpu/ipu
- Postman assertion
- Talking about the range of data that MySQL update will lock
- Openvino2022 dev tools installation and use
- The difference between RPC and restful
- 科创人·味多美CIO胡博:数字化是不流血的革命,正确答案藏在业务的田间地头
猜你喜欢

Apple doesn't need money, but it has no confidence in its content

VMware virtual machine setting static IP

The four stages of cloud computing development have finally been clarified

Vant component used in wechat applet

Mapstacks: data normalization and layered color layer loading

The Network Security Review Office launched a network security review on HowNet, saying that it "has a large amount of important data and sensitive information"

Haitai Advanced Technology | application of privacy computing technology in medical data protection

传统的IO存在什么问题?为什么引入零拷贝的?

After a few years in the testing industry, do you still know a little?

微信小程序中使用vant组件
随机推荐
Bytebase joins Alibaba cloud polardb open source database community
Steps of JMeter performance test
大一女生废话编程爆火!懂不懂编程的看完都拴Q了
Set up your own website (14)
微信小程序自定义tabBar
伯克利、MIT、剑桥、DeepMind等业内大佬线上讲座:迈向安全可靠可控的AI
顺序栈1.0版本
Analysis of errors in JSON conversion using objectmapper
Leetcode(455)——分发饼干
The difference between RPC and restful
Variable setting in postman
Leetcode (455) - distribute cookies
C语言实现扫雷(简易版)
Combination mode -- stock speculation has been cut into leeks? Come and try this investment strategy!
Leetcode(135)——分发糖果
Hosting service and SASE, enjoy the integration of network and security | phase I review
JMeter installation plug-in, adding [email protected] -Perfmon metric collector listener steps
What are the problems with traditional IO? Why is zero copy introduced?
Map跟object 的区别
Otaku can't save yuan universe