Skip to content

Commit

Permalink
add codes of split Audio
Browse files Browse the repository at this point in the history
  • Loading branch information
CheshireCC committed Dec 29, 2023
1 parent 6fac605 commit 5d92b6c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
6 changes: 3 additions & 3 deletions fasterWhisperGUIConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
"model_param": {
"localModel": true,
"onlineModel": false,
"model_path": "",
"model_path": "F:/WhisperModels/faster-whisper/large-v3-float32",
"modelName": 0,
"use_v3_model": true,
"device": 1,
"deviceIndex": "0",
"preciese": 0,
"thread_num": "4",
"num_worker": "1",
"download_root": "",
"download_root": "C:/Users/12059/.cache/huggingface/hub",
"local_files_only": false
},
"vad_param": {
Expand All @@ -30,7 +30,7 @@
},
"setting": {
"saveConfig": true,
"autoLoadModel": true,
"autoLoadModel": false,
"language": 2,
"huggingface_user_token": "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",
"autoGoToOutputPage": 2,
Expand Down
64 changes: 64 additions & 0 deletions faster_whisper_GUI/split_audio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import os
from PySide6.QtCore import (QThread, Signal)
import subprocess

class SplitAudioFileWithSpeakersWorker(QThread):
# 定义一个信号,用于在处理完成后发送结果
result_signal = Signal(str)

def __init__(self, segments_path_info_list:list, output_path, parent=None):
super().__init__(parent)
self.segments_path_info_list = segments_path_info_list
self.output_path = output_path

# 检查输出目录
if not os.path.exists(self.output_path):
os.makedirs(self.output_path)

def creatCommandLine(self, start_time, end_time, fileName, output_path, speaker):

output_fileName = self.getOutPutFileName(output_path, start_time, end_time, speaker)
commandLine = []
commandLine.append("ffmpeg")
commandLine.append("-i")
commandLine.append(fileName)
commandLine.append("-ss")
commandLine.append(start_time)
commandLine.append("-to")
commandLine.append(end_time)
commandLine.append(output_fileName)

def getOutPutFileName(self, output_path:str, start_time:str, end_time:str, speaker:str):
return os.path.join(output_path, f"{speaker}_{start_time.replace(':','_')}_{end_time.replace(':','_')}.wav")

def run(self):
self.is_running = True

for result in self.segments_path_info_list:
segments,path,info = result
_,file = os.path.split(path)
output_path = os.path.join(self.output_path, ".".join(file.split('.')[:-1]))

# 检查输出路径
if not os.path.exists(output_path):
os.makedirs(output_path)

for segment in segments:
if not segment.speaker: continue
start_time = segment.start_time
end_time = segment.end_time
speaker = segment.speaker

commandLine = self.creatCommandLine(start_time.replace(',','.'),end_time.replace(',','.'),path,output_path,speaker)

temp_process = subprocess.Popen(commandLine, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8", text=True,
creationflags=subprocess.CREATE_NO_WINDOW)
temp_process.wait()

# 完成后发送结果信号
result = "结束"
self.result_signal.emit(result)

def stop(self):
self.is_running = False
self.quit()
2 changes: 1 addition & 1 deletion faster_whisper_GUI/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.5.0"
__version__ = "0.5.2"
__FasterWhisper_version__ = "0.9.0"
__WhisperX_version__ = "3.1.1"
__Demucs_version__ = "v4.0"
Expand Down

0 comments on commit 5d92b6c

Please sign in to comment.