我是靠谱客的博主 美丽蛋挞,这篇文章主要介绍语音处理-批量文件处理静默区删除,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import fnmatch from pathlib import Path from scipy.io import wavfile import webrtcvad import struct from scipy.io.wavfile import write import os import numpy as np import matplotlib.pyplot as plt #开始将所有文件进行批处理操作 def find_all_files(files_path): """遍历指定文件夹所有指定类型文件""" p = Path(files_path) files_names = [] # 存储文件路径名称 for file in p.rglob('*.wav'): # 寻找所有txt文件 x = str(file).split('\')[-1] if fnmatch.fnmatch(x, '._*.wav'): continue else: files_names.append(str(file)) # 以字符串形式保存 return files_names def all_void_void(single_file_path,flag_session): #single_file_path = 'F:文件情感数据集未处理IEMOCAP_full_releaseSession1sentenceswavSes01F_impro01Ses01F_impro01_F013.wav' #single_file_path = 'E:codingpythonpythonfor_deleteVDSes01F_impro01_F000.wav' print(os.path.join(single_file_path)) sample_rate, samples = wavfile.read(os.path.join(single_file_path)) file_name = single_file_path.split("\")[-1] file_package = single_file_path.split("\")[-2] print(file_name) vad = webrtcvad.Vad() vad.set_mode(3) raw_samples = struct.pack("%dh" % len(samples), *samples) window_duration = 0.03 samples_per_window = int(window_duration * sample_rate + 0.3) bytes_per_sample = 2 segments = [] try: for start in np.arange(0, len(samples), samples_per_window): stop = min(start + samples_per_window, len(samples)) is_speech = vad.is_speech(raw_samples[start * bytes_per_sample: stop * bytes_per_sample], sample_rate=sample_rate) segments.append(dict( start=start, stop=stop, is_speech=is_speech)) except: try: speech_samples = np.concatenate( [samples[segment['start']:segment['stop']] for segment in segments if segment['is_speech']]) except: print('产生异常了第一次') try: speech_samples = np.concatenate( [samples[segment['start']:segment['stop']] for segment in segments if segment['is_speech']]) new_path = 'F:文件研究生组情感数据集已处理IEMOCAP_full_release\' + flag_session + 'sentenceswav\' + file_package # os.makedirs(new_path) if (os.path.exists(new_path)): print('1') else: os.makedirs(new_path) new_path =new_path+ '\'+file_name wavfile.write(new_path, sample_rate, speech_samples) except: print('产生异常了第二次') #new_path = 'F:文件研究生组情感数据集已处理IEMOCAP_full_releaseSession1sentenceswav\'+file_package # os.makedirs(new_path) # if(os.path.exists(new_path)): # print('1') # else: # os.makedirs(new_path) # new_path = new_path + '\'+file_name # wavfile.write(new_path, sample_rate, speech_samples) #Session_list =["Session1","Session2","Session3","Session4","Senssion5"] Session_list =["Session5"] for senssion_i in Session_list: files_name = find_all_files('F:文件情感数据集未处理IEMOCAP_full_release\'+senssion_i+'sentenceswav') for file_name in files_name: all_void_void(file_name,senssion_i)

最后

以上就是美丽蛋挞最近收集整理的关于语音处理-批量文件处理静默区删除的全部内容,更多相关语音处理-批量文件处理静默区删除内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(72)

评论列表共有 0 条评论

立即
投稿
返回
顶部