当前位置:网站首页>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
边栏推荐
- Nifi quick installation (stand-alone / cluster)
- Visitor model -- generation gap between young and middle-aged people
- [multi thread performance tuning] multi thread lock optimization (Part 1): optimization method of synchronized synchronization lock
- 刚购买了一个MYSQL数据库,提示已有实例,控制台登录实例要提供数据库账号,我如何知道数据库账号。
- Common member methods of the calendar class
- IDEA Dashboard
- The four stages of cloud computing development have finally been clarified
- Record a deletion bash_ Profile file
- yeb_ Back first day
- Apple doesn't need money, but it has no confidence in its content
猜你喜欢

Internet of things? Come and see Arduino on the cloud

The four stages of cloud computing development have finally been clarified

The difference between RPC and restful

Sleep revolution - find the right length of rest
![[performance tuning basics] performance tuning strategy](/img/83/be41a6a0c5c186d3fb3a120043c53f.jpg)
[performance tuning basics] performance tuning strategy

How to apply agile development ideas to other work

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"

Dongyuhui is not enough to bring goods to "rescue" live broadcast

Berkeley, MIT, Cambridge, deepmind and other industry leaders' online lectures: towards safe, reliable and controllable AI

使用gorm查询数据库时reflect: reflect.flag.mustBeAssignable using unaddressable value
随机推荐
Stackoverflow annual report 2022: what are developers' favorite databases?
Agency mode -- Jiangnan leather shoes factory
Sleep revolution - find the right length of rest
Internet of things? Come and see Arduino on the cloud
Create a multithreaded thread class
开放可编程基础设施(OPI)项目,重新定义DPU/IPU
Two fellow countrymen from Hunan have jointly launched a 10 billion yuan IPO
More than ten years' work experience is recommended at the bottom of the box: how much does it cost to find a job? See here! Brothers and sisters are recommended to collect and pay attention
Background operation retry gave up; KeeperErrorCode = ConnectionLoss
After screwing the screws in the factory for two years, I earned more than 10000 yuan a month by "testing" and counterattacked
顺序表的基本操作
Hongxiang Yunteng is compatible with dragon lizard operating system, and the product runs stably
After idea installs these plug-ins, the code can be written to heaven. My little sister also has to arrange it
Basic properties and ergodicity of binary tree
Responsibility chain mode -- through interview
Learn together and make progress together. Welcome to exchange
Talking about the range of data that MySQL update will lock
Prototype mode -- clone monster Army
Variable setting in postman
Material management system based on SSM (source code + document + database)