Skip to content

Commit

Permalink
添加了通过语音输入法转字幕的功能。将 Bilibili 视频链接放入
Browse files Browse the repository at this point in the history
  • Loading branch information
HaujetZhao committed Jul 30, 2020
1 parent e29d46f commit badb902
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions QuickCut.py
Original file line number Diff line number Diff line change
Expand Up @@ -3144,12 +3144,14 @@ def initGui(self):
self.voiceInputMethodSubtitleAuditokMinSilenceDurBox.setSingleStep(0.1)
self.voiceInputMethodSubtitleAuditokMinSilenceDurBox.setValue(0.2)

self.voiceInputMethodSubtitleAuditokEnergyThresholdHint = QLabel('声音能量阈值:')
self.voiceInputMethodSubtitleAuditokEnergyThresholdHint = HintLabel('声音能量阈值:')
self.voiceInputMethodSubtitleAuditokEnergyThresholdHint.hint = ' 它是用 log10 dot(x, x) / |x| 计算出的能量的 log 值'
self.voiceInputMethodSubtitleAuditokEnergyThresholdBox = QSpinBox()
self.voiceInputMethodSubtitleAuditokEnergyThresholdBox.setMinimum(1)
self.voiceInputMethodSubtitleAuditokEnergyThresholdBox.setValue(50)

self.voiceInputMethodSubtitleAuditokInputMethodSleepTimeHint = QLabel('输入法休息时间:')
self.voiceInputMethodSubtitleAuditokInputMethodSleepTimeHint = HintLabel('输入法休息时间:')
self.voiceInputMethodSubtitleAuditokInputMethodSleepTimeHint.hint = '每次输入完需要休息一下,否则在文字出来后很快再按下快捷键,语音输入法有可能响应不过来'
self.voiceInputMethodSubtitleAuditokInputMethodSleepTimeBox = QDoubleSpinBox()
self.voiceInputMethodSubtitleAuditokInputMethodSleepTimeBox.setMinimum(1)
self.voiceInputMethodSubtitleAuditokInputMethodSleepTimeBox.setSingleStep(0.2)
Expand Down Expand Up @@ -3283,7 +3285,7 @@ def voiceInputMethodSubtitleInputEditChanged(self):

# 帮助按钮
def voiceInputMethodSubtitleHelpButtonClicked(self):
webbrowser.open('www.baidu.com')
webbrowser.open('https://www.bilibili.com/video/BV1wT4y177kD/')

# 半自动
def voiceInputMethodSubtitleHalfAutoRunButtonClicked(self):
Expand Down Expand Up @@ -4457,7 +4459,7 @@ def startThread(self):
def pauseThread(self):
self.continueToTrans = False
self.pauseButton.setEnabled(False)
self.continueButton.setEnabled(True)


def printSignalReceived(self, text):
print(text)
Expand All @@ -4468,15 +4470,18 @@ def signalOfSubtitleReceived(self, srtObject):
self.finalResultBox.print(subtitle)
self.hintConsoleBox.print('第 %s 句识别完毕!\n' % self.thread.srtIndex)
if srtObject.content == '':
self.hintConsoleBox.print('片段识别结果是空白,有可能音频设置有误,请查看视频教程:\n')
self.hintConsoleBox.print('片段识别结果是空白,有可能音频设置有误,请查看视频教程:https://www.bilibili.com/video/BV1wT4y177kD/\n')
if self.mode == 0: # 只有在半自动模式,才在收到结果时恢复继续按键
self.continueButton.setEnabled(True)
else:
if self.continueToTrans == False: # 当在全自动模式,暂停后,收到了结果,让继续键变可用
self.continueButton.setEnabled(True)
if self.continueToTrans == True:
self.startThread()

def getFFmpegFinishSignal(self, wavFile): # 得到 wav 文件,
self.regionsList = self.transEngine.getRegions(wavFile) # 得到片段
self.wavFile = wavFile
self.regionsListLength = len(self.regionsList)
self.thread.transEngine = self.transEngine
self.thread.regionsList = self.regionsList
Expand All @@ -4501,6 +4506,10 @@ def closeEvent(self, a0: QCloseEvent) -> None:
self.srtFile.write(processedSubtitle)
except:
pass
try:
os.remove(self.wavFile)
except:
pass
try:
keyboard.release(self.shortcutOfInputMethod) # 这里是防止在关闭页面时,语音输入快捷键还按着
except:
Expand Down

0 comments on commit badb902

Please sign in to comment.