当前位置:网站首页>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
边栏推荐
- Undo log and redo log must be clear this time
- Record a deletion bash_ Profile file
- Hongxiang Yunteng is compatible with dragon lizard operating system, and the product runs stably
- Talking about the range of data that MySQL update will lock
- Dx12 engine development course progress - where does this course go
- How to enhance influence
- Basic operation of sequence table
- Haitai Advanced Technology | application of privacy computing technology in medical data protection
- 微信小程序自定义tabBar
- 伯克利、MIT、剑桥、DeepMind等业内大佬线上讲座:迈向安全可靠可控的AI
猜你喜欢
物联网?快来看 Arduino 上云啦
Grating diffraction
Combination mode -- stock speculation has been cut into leeks? Come and try this investment strategy!
伯克利、MIT、剑桥、DeepMind等业内大佬线上讲座:迈向安全可靠可控的AI
A/b test helps the growth of game business
网络安全审查办公室对知网启动网络安全审查
Shrimp skin test surface treated
Handling of garbled JMeter response data - three solutions
The Google File System (GFS) learning notes
微信小程序自定义tabBar
随机推荐
I feel that I am bald again when I help my children with their homework. I feel pity for my parents all over the world
Leetcode(455)——分发饼干
史上最全DPU厂商大盘点(上)
CVPR 2022 remembers Sun Jian! Tongji and Ali won the best student thesis award, and hekaiming was shortlisted
Batch capitalization of MySQL table names
Why do we always "give up halfway"?
How to apply agile development ideas to other work
Enjoy yuan mode -- a large number of flying dragons
I just purchased a MySQL database and prompted that there are already instances. The console login instance needs to provide a database account. How do I know the database account.
[multi thread performance tuning] multi thread lock optimization (Part 1): optimization method of synchronized synchronization lock
Prototype mode -- clone monster Army
Implement the redis simple client customized based on socket
Selenium crawl notes
Mapstacks: data normalization and layered color layer loading
Procedural life: a few things you should know when entering the workplace
Analysis of errors in JSON conversion using objectmapper
What does virtualization mean? What technologies are included? What is the difference with private cloud?
When querying the database with Gorm, reflect: reflect flag. mustBeAssignable using unaddressable value
Visitor model -- generation gap between young and middle-aged people
It was Tencent who jumped out of the job with 26k. It really wiped my ass with sandpaper. It gave me a hand