我是把so-vits中小工具,分析源码然后提取出来了。以后可以写在自己的程序里。
——-流程(这是我做的流程,你可以不用看)
从开源代码中快速获取自己需要的东西
如果有界面f12看他里面的接口,然后在源码中全局搜索,没有接口比如socket,看他的消息字段,然后推测。然后提取补齐代码就行了
——-
你需要看的
提取出来有3个类
run.py是我自己写的
其他是我提取的源码,首先你得install一些包
numpy,librosa,soundfile
slicer2.py
import numpy as np
# This function is obtained from librosa.
def get_rms(
y,
*,
frame_length=2048,
hop_length=512,
pad_mode="constant",
):
padding = (int(frame_length // 2), int(frame_length // 2))
y = np.pad(y, padding, mode=pad_mode)
axis = -1
# put our new within-frame axis at the end for now
out_strides = y.strides + tuple([y.strides[axis]])
# Reduce the shape on the framing axis
x_shape_trimmed = list(y.shape)
x_shape_trimmed[axis] -= frame_length - 1
out_shape = tuple(x_shape_trimmed) + tuple([frame_length])
xw = np.lib.stride_tricks.as_strided(
y, shape=out_shape, strides=out_strides
)
if axis = min_interval >= hop_size:
raise ValueError('The following condition must be satisfied: min_length >= min_interval >= hop_size')
if not max_sil_kept >= hop_size:
raise ValueError('The following condition must be satisfied: max_sil_kept >= hop_size')
min_interval = sr * min_interval / 1000
self.threshold = 10 ** (threshold / 20.)
self.hop_size = round(sr * hop_size / 1000)
self.win_size = min(round(min_interval), 4 * self.hop_size)
self.min_length = round(sr * min_length / 1000 / self.hop_size)
self.min_interval = round(min_interval / self.hop_size)
self.max_sil_kept = round(sr * max_sil_kept / 1000 / self.hop_size)
def _apply_slice(self, waveform, begin, end):
if len(waveform.shape) > 1:
return waveform[:, begin * self.hop_size: min(waveform.shape[1], end * self.hop_size)]
else:
return waveform[begin * self.hop_size: min(waveform.shape[0], end * self.hop_size)]
# @timeit
def slice(self, waveform):
if len(waveform.shape) > 1:
samples = waveform.mean(axis=0)
else:
samples = waveform
if samples.shape[0] self.max_sil_kept
need_slice_middle = i - silence_start >= self.min_interval and i - clip_start >= self.min_length
if not is_leading_silence and not need_slice_middle:
silence_start = None
continue
# Need slicing. Record the range of silent frames to be removed.
if i - silence_start = self.min_interval:
silence_end = min(total_frames, silence_start + self.max_sil_kept)
pos = rms_list[silence_start: silence_end + 1].argmin() + silence_start
sil_tags.append((pos, total_frames + 1))
# Apply and return slices.
if len(sil_tags) == 0:
return [waveform]
else:
chunks = []
if sil_tags[0][0] > 0:
chunks.append(self._apply_slice(waveform, 0, sil_tags[0][0]))
for i in range(len(sil_tags) - 1):
chunks.append(self._apply_slice(waveform, sil_tags[i][1], sil_tags[i + 1][0]))
if sil_tags[-1][1] 1:
chunk = chunk.T
soundfile.write(os.path.join(out, f'%s_%d.wav' % (os.path.basename(args.audio).rsplit('.', maxsplit=1)[0], i)), chunk, sr)
if __name__ == '__main__':
main()
auto_slicer.py
import os
import numpy as np
import librosa
import soundfile as sf
from slicer2 import Slicer
class AutoSlicer:
def __init__(self):
self.slicer_params = {
"threshold": -40,
"min_length": 5000,
"min_interval": 300,
"hop_size": 10,
"max_sil_kept": 500,
}
self.original_min_interval = self.slicer_params["min_interval"]
def auto_slice(self, filename, input_dir, output_dir, max_sec):
audio, sr = librosa.load(os.path.join(input_dir, filename), sr=None, mono=False)
slicer = Slicer(sr=sr, **self.slicer_params)
chunks = slicer.slice(audio)
files_to_delete = []
for i, chunk in enumerate(chunks):
if len(chunk.shape) > 1:
chunk = chunk.T
output_filename = f"{os.path.splitext(filename)[0]}_{i}"
output_filename = "".join(c for c in output_filename if c.isascii() or c == "_") + ".wav"
output_filepath = os.path.join(output_dir, output_filename)
sf.write(output_filepath, chunk, sr)
#Check and re-slice audio that more than max_sec.
while True:
new_audio, sr = librosa.load(output_filepath, sr=None, mono=False)
if librosa.get_duration(y=new_audio, sr=sr) = self.slicer_params["hop_size"]:
new_chunks = Slicer(sr=sr, **self.slicer_params).slice(new_audio)
for j, new_chunk in enumerate(new_chunks):
if len(new_chunk.shape) > 1:
new_chunk = new_chunk.T
new_output_filename = f"{os.path.splitext(output_filename)[0]}_{j}.wav"
sf.write(os.path.join(output_dir, new_output_filename), new_chunk, sr)
files_to_delete.append(output_filepath)
else:
break
self.slicer_params["min_interval"] = self.original_min_interval
for file_path in files_to_delete:
if os.path.exists(file_path):
os.remove(file_path)
def merge_short(self, output_dir, max_sec, min_sec):
short_files = []
for filename in os.listdir(output_dir):
filepath = os.path.join(output_dir, filename)
if filename.endswith(".wav"):
audio, sr = librosa.load(filepath, sr=None, mono=False)
duration = librosa.get_duration(y=audio, sr=sr)
if duration 1:
output_audio = output_audio.T
output_filename = f"merged_{len(os.listdir(output_dir))}.wav"
sf.write(os.path.join(output_dir, output_filename), output_audio, sr)
merged_audio =
current_duration = duration
os.remove(filepath)
if merged_audio and current_duration >= min_sec:
output_audio = np.concatenate(merged_audio, axis=-1)
if len(output_audio.shape) > 1:
output_audio = output_audio.T
output_filename = f"merged_{len(os.listdir(output_dir))}.wav"
sf.write(os.path.join(output_dir, output_filename), output_audio, sr)
def slice_count(self, input_dir, output_dir):
orig_duration = final_duration = 0
服务器托管网 for file in os.listdir(input_dir):
if file.endswith(".wav"):
_audio, _sr = librosa.load(os.path.join(input_dir, file), sr=None, mono=False)
orig_duration += librosa.get_duration(y=_audio, sr=_sr)
wav_files = [file for file in os.listdir(output_dir) if file.endswith(".wav")]
num_files = len(wav_files)
max_duration = -1
min_duration = float("inf")
for file in wav_files:
file_path = os.path.join(output_dir, file)
audio, sr = librosa.load(file_path, sr=None, mono=False)
duration = librosa.get_duration(y=audio, sr=sr)
final_duration += float(duration)
if duration > max_duration:
max_duration = float(duration)
if duration
run.py
import os
from auto_slicer import AutoSlicer
import librosa
def slicer_fn(input_dir, output_dir, process_method, max_sec, min_sec):
if output服务器托管网_dir == "":
return "请先选择输出的文件夹"
if output_dir == input_dir:
return "输出目录不能和输入目录相同"
slicer = AutoSlicer()
if os.path.exists(output_dir) is not True:
os.makedirs(output_dir)
for filename in os.listdir(input_dir):
if filename.lower().endswith(".wav"):
slicer.auto_slice(filename, input_dir, output_dir, max_sec)
if process_method == "丢弃":
for filename in os.listdir(output_dir):
if filename.endswith(".wav"):
filepath = os.path.join(output_dir, filename)
audio, sr = librosa.load(filepath, sr=None, mono=False)
if librosa.get_duration(y=audio, sr=sr)
测试输入
得到
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
1. 明道云用户使用场景:市场营销人员常需要为公司新推出的产品撰写宣传介绍,这个流程需要他们先登录明道云账号,然后将产品卖点的关键词录入表单,接着将这些关键词同步到智谱AI平台生成一系列标题,他们需要再次同步这些标题到表单汇总,并在小组讨论后选择心仪的标题,将…