Skip to content

Commit

Permalink
将 ali-nls sdk 放到了 pypi 库,可以直接从 pypi 安装了。解决了启动后不能自动启动 CapsWriter 的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
HaujetZhao committed Aug 15, 2020
1 parent 331006b commit 16d9c81
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 59 deletions.
103 changes: 47 additions & 56 deletions QuickCut/QuickCut.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest


import ali_speech
from ali_speech.callbacks import SpeechRecognizerCallback
from ali_speech.constant import ASRFormat
from ali_speech.constant import ASRSampleRate

from audiotsm import phasevocoder
from audiotsm.io.wav import WavReader, WavWriter
Expand All @@ -65,7 +68,7 @@
preferenceTableName = 'preference'
styleFile = './style.css' # 样式表的路径
finalCommand = ''
version = 'V1.6.5'
version = 'V1.6.6'



Expand Down Expand Up @@ -3567,13 +3570,11 @@ def __init__(self):
self.capsWriterThread = None
self.initGui()


def initGui(self):
self.masterLayout = QVBoxLayout()

self.widgetLayout = QGridLayout()

self.setLayout(self.masterLayout)

self.subtitleEngineLabel = QLabel(self.tr('字幕语音 API:'))
self.subtitleEngineComboBox = QComboBox()
########改用主数据库
Expand Down Expand Up @@ -3625,17 +3626,16 @@ def initGui(self):

self.masterLayout.addStretch(0)

self.enableButton.clicked.connect(self.capsWriterEnabled)
self.disableButton.clicked.connect(self.capsWriterDisabled)

def initCapsWriterStatus(self):
cursor = conn.cursor()
result = cursor.execute('select value from %s where item = "%s";' % (preferenceTableName, 'CapsWriterEnabled'))
if result.fetchone()[0] == 'False':
self.disableButton.setChecked(True)
self.disableButton.click()
else:
self.enableButton.setChecked(True)
self.capsWriterEnabled()

self.enableButton.clicked.connect(self.capsWriterEnabled)
self.disableButton.clicked.connect(self.capsWriterDisabled)
# self.
self.enableButton.click()

def switchEnableButtonStatus(self):
if self.subtitleEngineComboBox.currentText() == '':
Expand Down Expand Up @@ -5920,14 +5920,6 @@ def print(self, text):

def run(self):
try:
try:
import ali_speech
from ali_speech.callbacks import SpeechRecognizerCallback
from ali_speech.constant import ASRFormat
from ali_speech.constant import ASRSampleRate
except:
self.outputBox.print('系统未安装阿里语音引擎 sdk,请使用“https://help.aliyun.com/document_detail/120693.html”文章里的方法安装阿里云语音识别 sdk,才能使用该功能 \n\n')
return
self.client = ali_speech.NlsClient()
self.client.set_log_level('ERROR') # 设置 client 输出日志信息的级别:DEBUG、INFO、WARNING、ERROR
self.recognizer = self.get_recognizer(self.client, self.appKey)
Expand All @@ -5945,45 +5937,44 @@ def run(self):
except:
pass
return
try:
class MyCallback(SpeechRecognizerCallback):
"""
构造函数的参数没有要求,可根据需要设置添加
示例中的name参数可作为待识别的音频文件名,用于在多线程中进行区分
"""
def __init__(self, name='default'):
self._name = name
self.message = None
self.outputBox = mainWindow.capsWriterTab.outputBox

def on_started(self, message):
# print('MyCallback.OnRecognitionStarted: %s' % message)
pass

def on_result_changed(self, message):
self.outputBox.print(self.tr('任务信息: task_id: %s, result: %s') % (message['header']['task_id'], message['payload']['result']))
class MyCallback(SpeechRecognizerCallback):
"""
构造函数的参数没有要求,可根据需要设置添加
示例中的name参数可作为待识别的音频文件名,用于在多线程中进行区分
"""
def __init__(self, name='default'):
self._name = name
self.message = None
global mainWindow
self.outputBox = mainWindow.capsWriterTab.outputBox

def on_started(self, message):
# print('MyCallback.OnRecognitionStarted: %s' % message)
pass

def on_completed(self, message):
if message != self.message:
self.message = message
self.outputBox.print(mainWindow.capsWriterTab.tr('结果: %s') % (message['payload']['result']))
result = message['payload']['result']
try:
if result[-1] == '。': # 如果最后一个符号是句号,就去掉。
result = result[0:-1]
except Exception as e:
pass
keyboard.press_and_release('caps lock') # 再按下大写锁定键,还原大写锁定
keyboard.write(result) # 输入识别结果
def on_result_changed(self, message):
self.outputBox.print(self.tr('任务信息: task_id: %s, result: %s') % (message['header']['task_id'], message['payload']['result']))

def on_completed(self, message):
if message != self.message:
self.message = message
self.outputBox.print(mainWindow.capsWriterTab.tr('结果: %s') % (message['payload']['result']))
result = message['payload']['result']
try:
if result[-1] == '。': # 如果最后一个符号是句号,就去掉。
result = result[0:-1]
except Exception as e:
pass
keyboard.press_and_release('caps lock') # 再按下大写锁定键,还原大写锁定
keyboard.write(result) # 输入识别结果

def on_task_failed(self, message):
self.outputBox.print(self.tr('识别任务失败: %s') % message)
def on_task_failed(self, message):
self.outputBox.print(self.tr('识别任务失败: %s') % message)

def on_channel_closed(self):
# print('MyCallback.OnRecognitionChannelClosed')
pass
except:
pass
def on_channel_closed(self):
# print('MyCallback.OnRecognitionChannelClosed')
pass

def get_token(self):
newConn = sqlite3.connect(dbname)
Expand Down Expand Up @@ -6019,7 +6010,6 @@ def get_token(self):
def get_recognizer(self, client, appkey):
token = self.get_token()
audio_name = 'none'

callback = self.MyCallback(audio_name)
recognizer = client.create_recognizer(callback)
recognizer.set_appkey(appkey)
Expand Down Expand Up @@ -7411,6 +7401,7 @@ def main():
else:
pass
mainWindow = MainWindow()
mainWindow.capsWriterTab.initCapsWriterStatus() # 只有在 mainWindow 初始化完成后,才能启动 capsWriter
if platfm == 'Windows':
tray = SystemTray(QIcon('icon.ico'), mainWindow)
else:
Expand Down
1 change: 1 addition & 0 deletions QuickCut/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ keyboard
numpy
setuptools
aliyun-python-sdk-core
alibabacloud-nls-java-sdk
PyQt5
audiotsm
scipy
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding=utf-8
# python setup.py sdist build
# python setup.py sdist –formats = gztar,zip
# twine upload "dist/Quick Cut-1.6.6.post3.tar.gz"
# twine upload "dist/Quick Cut-1.6.6.post5.tar.gz"
# 这是用于上传 pypi 前打包用的


Expand All @@ -15,7 +15,7 @@

setup(
name='Quick Cut',
version='1.6.6.post3',
version='1.6.6.post5',
description=(
'一款轻量、强大、好用的视频处理软件。'
),
Expand All @@ -32,7 +32,8 @@
'keyboard',
'numpy',
'scipy',
'aliyun-python-sdk-core',
'aliyun-python-sdk-core',
'alibabacloud-nls-java-sdk',
'PyQt5',
'audiotsm',
'cos-python-sdk-v5',
Expand Down

0 comments on commit 16d9c81

Please sign in to comment.