Commit 7b6f8043 by mucece

Merge remote-tracking branch 'TV_OCR/master' into muce

parents b0417193 2c4e0dd0
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -51,7 +51,7 @@
[],
False,
False,
1638438345,
1645430499,
[('runw.exe',
'D:\\python3.8\\lib\\site-packages\\PyInstaller\\bootloader\\Windows-64bit\\runw.exe',
'EXECUTABLE')])
......@@ -15,6 +15,7 @@ IMPORTANT: Do NOT post this list to the issue-tracker. Use it as a basis for
yourself tracking down the missing module. Thanks!
missing module named pyimod03_importers - imported by D:\python3.8\Lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgutil.py (top-level), D:\python3.8\Lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgres.py (top-level)
missing module named _manylinux - imported by pkg_resources._vendor.packaging.tags (delayed, optional), packaging._manylinux (delayed, optional), setuptools._vendor.packaging.tags (delayed, optional)
missing module named _posixshmem - imported by multiprocessing.resource_tracker (conditional), multiprocessing.shared_memory (conditional)
missing module named multiprocessing.set_start_method - imported by multiprocessing (top-level), multiprocessing.spawn (top-level)
missing module named multiprocessing.get_start_method - imported by multiprocessing (top-level), multiprocessing.spawn (top-level)
......@@ -29,27 +30,26 @@ missing module named multiprocessing.TimeoutError - imported by multiprocessing
missing module named _scproxy - imported by urllib.request (conditional)
missing module named termios - imported by tty (top-level), getpass (optional)
missing module named pwd - imported by posixpath (delayed, conditional), shutil (optional), tarfile (optional), pathlib (delayed, conditional, optional), http.server (delayed, optional), webbrowser (delayed), netrc (delayed, conditional), getpass (delayed), distutils.util (delayed, conditional, optional), distutils.archive_util (optional)
missing module named 'org.python' - imported by copy (optional), setuptools.sandbox (conditional), xml.sax (delayed, conditional)
missing module named 'java.lang' - imported by platform (delayed, optional), xml.sax._exceptions (conditional)
missing module named multiprocessing.BufferTooShort - imported by multiprocessing (top-level), multiprocessing.connection (top-level)
missing module named multiprocessing.AuthenticationError - imported by multiprocessing (top-level), multiprocessing.connection (top-level)
missing module named asyncio.DefaultEventLoopPolicy - imported by asyncio (delayed, conditional), asyncio.events (delayed, conditional)
missing module named 'org.python' - imported by pickle (optional), setuptools.sandbox (conditional), xml.sax (delayed, conditional)
missing module named org - imported by pickle (optional)
missing module named _uuid - imported by uuid (optional)
missing module named netbios - imported by uuid (delayed)
missing module named win32wnet - imported by uuid (delayed)
missing module named readline - imported by cmd (delayed, conditional, optional), code (delayed, conditional, optional), pdb (delayed, optional)
missing module named __builtin__ - imported by torch._six (conditional), pkg_resources._vendor.pyparsing (conditional), pyparsing (conditional), setuptools._vendor.pyparsing (conditional)
missing module named ordereddict - imported by pkg_resources._vendor.pyparsing (optional), pyparsing (optional), setuptools._vendor.pyparsing (optional)
missing module named org - imported by copy (optional)
missing module named _manylinux - imported by pkg_resources._vendor.packaging.tags (delayed, optional), packaging._manylinux (delayed, optional), setuptools._vendor.packaging.tags (delayed, optional)
missing module named grp - imported by shutil (optional), tarfile (optional), pathlib (delayed), distutils.archive_util (optional)
missing module named 'pkg_resources.extern.pyparsing' - imported by pkg_resources._vendor.packaging.markers (top-level), pkg_resources._vendor.packaging.requirements (top-level)
missing module named 'win32com.shell' - imported by pkg_resources._vendor.appdirs (conditional, optional)
missing module named 'com.sun' - imported by pkg_resources._vendor.appdirs (delayed, conditional, optional)
missing module named com - imported by pkg_resources._vendor.appdirs (delayed)
missing module named win32api - imported by distutils.msvccompiler (optional), pkg_resources._vendor.appdirs (delayed, conditional, optional)
missing module named win32com - imported by pkg_resources._vendor.appdirs (delayed)
missing module named _winreg - imported by platform (delayed, optional), pkg_resources._vendor.appdirs (delayed, conditional)
missing module named 'pkg_resources.extern.pyparsing' - imported by pkg_resources._vendor.packaging.markers (top-level), pkg_resources._vendor.packaging.requirements (top-level)
missing module named pkg_resources.extern.packaging - imported by pkg_resources.extern (top-level), pkg_resources (top-level)
missing module named pkg_resources.extern.appdirs - imported by pkg_resources.extern (top-level), pkg_resources (top-level)
missing module named vms_lib - imported by platform (delayed, conditional, optional)
......@@ -98,7 +98,7 @@ missing module named 'PySide6.QtGui' - imported by PIL.ImageQt (conditional, opt
missing module named 'PyQt6.QtGui' - imported by PIL.ImageQt (conditional, optional)
missing module named dummy_thread - imported by cffi.lock (conditional, optional)
missing module named thread - imported by cffi.lock (conditional, optional), cffi.cparser (conditional, optional)
missing module named 'setuptools.extern.pyparsing' - imported by setuptools._vendor.packaging.markers (top-level), setuptools._vendor.packaging.requirements (top-level)
missing module named 'setuptools.extern.pyparsing' - imported by setuptools._vendor.packaging.requirements (top-level), setuptools._vendor.packaging.markers (top-level)
missing module named 'setuptools.extern.more_itertools' - imported by setuptools.dist (top-level), setuptools.package_index (top-level), setuptools.msvc (top-level)
missing module named 'setuptools.extern.packaging.version' - imported by setuptools.config (top-level), setuptools.msvc (top-level)
missing module named wincertstore - imported by setuptools.ssl_support (delayed, optional)
......
......@@ -41,6 +41,7 @@ imports:
&#8226; <a href="#collections">collections</a>
&#8226; <a href="#collections.abc">collections.abc</a>
&#8226; <a href="#copyreg">copyreg</a>
&#8226; <a href="#difflib">difflib</a>
&#8226; <a href="#encodings">encodings</a>
&#8226; <a href="#encodings.aliases">encodings.aliases</a>
&#8226; <a href="#encodings.ascii">encodings.ascii</a>
......@@ -444,7 +445,7 @@ imported by:
<a target="code" href="" type="text/plain"><tt>'org.python'</tt></a>
<span class="moduletype">MissingModule</span> <div class="import">
imported by:
<a href="#pickle">pickle</a>
<a href="#copy">copy</a>
&#8226; <a href="#setuptools.sandbox">setuptools.sandbox</a>
&#8226; <a href="#xml.sax">xml.sax</a>
......@@ -661,7 +662,6 @@ imports:
&#8226; <a href="#PIL.ImageShow">PIL.ImageShow</a>
&#8226; <a href="#PIL.ImageStat">PIL.ImageStat</a>
&#8226; <a href="#PIL.ImageTk">PIL.ImageTk</a>
&#8226; <a href="#PIL.Jpeg2KImagePlugin">PIL.Jpeg2KImagePlugin</a>
&#8226; <a href="#PIL.JpegImagePlugin">PIL.JpegImagePlugin</a>
&#8226; <a href="#PIL.PaletteFile">PIL.PaletteFile</a>
&#8226; <a href="#PIL.PdfParser">PIL.PdfParser</a>
......@@ -1824,8 +1824,7 @@ imports:
</div>
<div class="import">
imported by:
<a href="#PIL">PIL</a>
&#8226; <a href="#PIL.IcnsImagePlugin">PIL.IcnsImagePlugin</a>
<a href="#PIL.IcnsImagePlugin">PIL.IcnsImagePlugin</a>
&#8226; <a href="#PIL.Image">PIL.Image</a>
</div>
......@@ -6828,8 +6827,8 @@ imported by:
<a target="code" href="///D:/python3.8/lib/copy.py" type="text/plain"><tt>copy</tt></a>
<span class="moduletype">SourceModule</span> <div class="import">
imports:
<a href="#copyreg">copyreg</a>
&#8226; <a href="#org">org</a>
<a href="#'org.python'">'org.python'</a>
&#8226; <a href="#copyreg">copyreg</a>
&#8226; <a href="#types">types</a>
&#8226; <a href="#weakref">weakref</a>
......@@ -7400,6 +7399,7 @@ imports:
imported by:
<a href="#difflib">difflib</a>
&#8226; <a href="#doctest">doctest</a>
&#8226; <a href="#initial.py">initial.py</a>
&#8226; <a href="#numpy.testing._private.utils">numpy.testing._private.utils</a>
&#8226; <a href="#test_rec_infer_live">test_rec_infer_live</a>
&#8226; <a href="#torch.jit">torch.jit</a>
......@@ -23540,7 +23540,7 @@ imported by:
<a target="code" href="" type="text/plain"><tt>org</tt></a>
<span class="moduletype">MissingModule</span> <div class="import">
imported by:
<a href="#copy">copy</a>
<a href="#pickle">pickle</a>
</div>
......@@ -23855,7 +23855,6 @@ imports:
<a href="#packaging">packaging</a>
&#8226; <a href="#packaging.__about__">packaging.__about__</a>
&#8226; <a href="#packaging._manylinux">packaging._manylinux</a>
&#8226; <a href="#packaging._musllinux">packaging._musllinux</a>
&#8226; <a href="#packaging.version">packaging.version</a>
&#8226; <a href="#pkg_resources">pkg_resources</a>
......@@ -23945,8 +23944,7 @@ imports:
</div>
<div class="import">
imported by:
<a href="#packaging">packaging</a>
&#8226; <a href="#packaging.tags">packaging.tags</a>
<a href="#packaging.tags">packaging.tags</a>
&#8226; <a href="#pkg_resources">pkg_resources</a>
</div>
......@@ -24205,8 +24203,7 @@ imported by:
<a target="code" href="///D:/python3.8/lib/pickle.py" type="text/plain"><tt>pickle</tt></a>
<span class="moduletype">SourceModule</span> <div class="import">
imports:
<a href="#'org.python'">'org.python'</a>
&#8226; <a href="#_compat_pickle">_compat_pickle</a>
<a href="#_compat_pickle">_compat_pickle</a>
&#8226; <a href="#_pickle">_pickle</a>
&#8226; <a href="#codecs">codecs</a>
&#8226; <a href="#copyreg">copyreg</a>
......@@ -24214,6 +24211,7 @@ imports:
&#8226; <a href="#functools">functools</a>
&#8226; <a href="#io">io</a>
&#8226; <a href="#itertools">itertools</a>
&#8226; <a href="#org">org</a>
&#8226; <a href="#pprint">pprint</a>
&#8226; <a href="#re">re</a>
&#8226; <a href="#struct">struct</a>
# -*- coding:utf-8 -*-
#
# author: iflytek
#
# 本demo测试时运行的环境为:Windows + Python3.7
# 本demo测试成功运行时所安装的第三方库及其版本如下,您可自行逐一或者复制到一个新的txt文件利用pip一次性安装:
# cffi==1.12.3
# gevent==1.4.0
# greenlet==0.4.15
# pycparser==2.19
# six==1.12.0
# websocket==0.2.1
# websocket-client==0.56.0
#
# 语音听写流式 WebAPI 接口调用示例 接口文档(必看):https://doc.xfyun.cn/rest_api/语音听写(流式版).html
# webapi 听写服务参考帖子(必看):http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=38947&extra=
# 语音听写流式WebAPI 服务,热词使用方式:登陆开放平台https://www.xfyun.cn/后,找到控制台--我的应用---语音听写(流式)---服务管理--个性化热词,
# 设置热词
# 注意:热词只能在识别的时候会增加热词的识别权重,需要注意的是增加相应词条的识别率,但并不是绝对的,具体效果以您测试为准。
# 语音听写流式WebAPI 服务,方言试用方法:登陆开放平台https://www.xfyun.cn/后,找到控制台--我的应用---语音听写(流式)---服务管理--识别语种列表
# 可添加语种或方言,添加后会显示该方言的参数值
# 错误码链接:https://www.xfyun.cn/document/error-code (code返回错误码时必看)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import websocket
import datetime
import hashlib
import base64
import hmac
import json
from urllib.parse import urlencode
import time
import ssl
from wsgiref.handlers import format_date_time
from datetime import datetime
from time import mktime
import _thread as thread
STATUS_FIRST_FRAME = 0 # 第一帧的标识
STATUS_CONTINUE_FRAME = 1 # 中间帧标识
STATUS_LAST_FRAME = 2 # 最后一帧的标识
class Ws_Param1(object):
# 初始化
def __init__(self):
self.APPID = '5d1ad3d5'
self.APIKey ='b7c216ce0834468cc372f3f00d2d7b36'
self.APISecret = '28c7560f3d6ec49f8c8750b76002ab34'
self.AudioFile='luyin.wav'
self.result=""
# 公共参数(common)
self.CommonArgs = {"app_id": self.APPID}
# 业务参数(business),更多个性化参数可在官网查看
self.BusinessArgs = {"domain": "iat", "language": "zh_cn", "accent": "mandarin", "vinfo":1,"vad_eos":10000,"ptt":0}
# 生成url
def create_url(self):
url = 'wss://ws-api.xfyun.cn/v2/iat'
# 生成RFC1123格式的时间戳
now = datetime.now()
date = format_date_time(mktime(now.timetuple()))
# 拼接字符串
signature_origin = "host: " + "ws-api.xfyun.cn" + "\n"
signature_origin += "date: " + date + "\n"
signature_origin += "GET " + "/v2/iat " + "HTTP/1.1"
# 进行hmac-sha256进行加密
signature_sha = hmac.new(self.APISecret.encode('utf-8'), signature_origin.encode('utf-8'),
digestmod=hashlib.sha256).digest()
signature_sha = base64.b64encode(signature_sha).decode(encoding='utf-8')
authorization_origin = "api_key=\"%s\", algorithm=\"%s\", headers=\"%s\", signature=\"%s\"" % (
self.APIKey, "hmac-sha256", "host date request-line", signature_sha)
authorization = base64.b64encode(authorization_origin.encode('utf-8')).decode(encoding='utf-8')
# 将请求的鉴权参数组合为字典
v = {
"authorization": authorization,
"date": date,
"host": "ws-api.xfyun.cn"
}
# 拼接鉴权参数,生成url
url = url + '?' + urlencode(v)
# print("date: ",date)
# print("v: ",v)
# 此处打印出建立连接时候的url,参考本demo的时候可取消上方打印的注释,比对相同参数时生成的url与自己代码生成的url是否一致
# print('websocket url :', url)
return url
# 收到websocket消息的处理
def on_message(ws, message):
try:
code = json.loads(message)["code"]
sid = json.loads(message)["sid"]
if code != 0:
errMsg = json.loads(message)["message"]
print("sid:%s call error:%s code is:%s" % (sid, errMsg, code))
else:
data = json.loads(message)["data"]["result"]["ws"]
# print(json.loads(message)["data"]["result"])
global result
# result=[]
for i in data:
for w in i["cw"]:
wsParam1.result += w["w"]
# print(result)
# print("sid:%s call success!,data is:%s" % (sid, json.dumps(data, ensure_ascii=False)))
# for i in len(data):
# print(data[int(i)]["cw"][0]["w"])
except Exception as e:
print("receive msg,but parse exception:", e)
# 收到websocket错误的处理
def on_error(ws, error):
print("### error:", error)
# 收到websocket关闭的处理
def on_close(ws):
print("### closed ###")
# 收到websocket连接建立的处理
def on_open(ws):
def run(*args):
frameSize = 8000 # 每一帧的音频大小
intervel = 0.04 # 发送音频间隔(单位:s)
status = STATUS_FIRST_FRAME # 音频的状态信息,标识音频是第一帧,还是中间帧、最后一帧
with open(wsParam1.AudioFile, "rb") as fp:
while True:
buf = fp.read(frameSize)
# 文件结束
if not buf:
status = STATUS_LAST_FRAME
# 第一帧处理
# 发送第一帧音频,带business 参数
# appid 必须带上,只需第一帧发送
if status == STATUS_FIRST_FRAME:
d = {"common": wsParam1.CommonArgs,
"business": wsParam1.BusinessArgs,
"data": {"status": 0, "format": "audio/L16;rate=16000",
"audio": str(base64.b64encode(buf), 'utf-8'),
"encoding": "raw"}}
d = json.dumps(d)
ws.send(d)
status = STATUS_CONTINUE_FRAME
# 中间帧处理
elif status == STATUS_CONTINUE_FRAME:
d = {"data": {"status": 1, "format": "audio/L16;rate=16000",
"audio": str(base64.b64encode(buf), 'utf-8'),
"encoding": "raw"}}
ws.send(json.dumps(d))
# 最后一帧处理
elif status == STATUS_LAST_FRAME:
d = {"data": {"status": 2, "format": "audio/L16;rate=16000",
"audio": str(base64.b64encode(buf), 'utf-8'),
"encoding": "raw"}}
ws.send(json.dumps(d))
time.sleep(1)
break
# 模拟音频采样间隔
time.sleep(intervel)
ws.close()
thread.start_new_thread(run, ())
def translation():
# print(wsParam)
# wsParam1=ws
time1 = datetime.now()
global wsParam1
wsParam1 = Ws_Param1()
websocket.enableTrace(False)
wsUrl = wsParam1.create_url()
ws = websocket.WebSocketApp(wsUrl, on_message=on_message, on_error=on_error, on_close=on_close)
ws.on_open = on_open
ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})
time2 = datetime.now()
print(time2 - time1)
return wsParam1.result
if __name__ == "__main__":
# 测试时候在此处正确填写相关信息即可运行
result=translation()
time.sleep(3)
print(result)
import os
import sys
import time
import wave
import numpy as np
import pyaudio
from scipy import fftpack
"""
监控麦克风,以及进行录音
"""
class record():
#判断声音是否超过一定数值
def recording_time(self):
CHUNK = 1024 # 块大小
FORMAT = pyaudio.paInt16 # 每次采集的位数
CHANNELS = 1
RATE = 16000 # 采样率:每秒采集数据的次数
self.end_time = None
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK)
print("录音中")
frames = []
time1 = time.time()
while True:
data = stream.read(CHUNK)
rt_data = np.frombuffer(data, np.dtype('<i2'))
# print(rt_data*10)
# 傅里叶变换
fft_temp_data = fftpack.fft(rt_data, rt_data.size, overwrite_x=True)
fft_data = np.abs(fft_temp_data)[0:fft_temp_data.size // 2 + 1]
fa_data = sum(fft_data) // len(fft_data)
print(fa_data)
time2 = time.time()
if fa_data > 2000:
self.end_time = time.time()
print("有反馈")
return self.end_time
elif time2 - time1 > 3:
return self.end_time
def recording(self):
CHUNK = 1024 # 块大小
FORMAT = pyaudio.paInt16 # 每次采集的位数
CHANNELS = 1
RATE = 16000 # 采样率:每秒采集数据的次数
self.end_time=None
WAVE_OUTPUT_FILENAME = "luyin.wav" # 文件存放位置
self.break_luyin = False
self.start_luyin = False
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK)
print("录音中")
frames = []
data_list = [0] * 60
# while not self.break_luyin:
time_start=time.time()
while True:
if self.break_luyin or (time.time()-time_start)>10:
break
data = stream.read(CHUNK)
rt_data = np.frombuffer(data, np.dtype('<i2'))
# print(rt_data*10)
# 傅里叶变换
fft_temp_data = fftpack.fft(rt_data, rt_data.size, overwrite_x=True)
fft_data = np.abs(fft_temp_data)[0:fft_temp_data.size // 2 + 1]
fa_data = sum(fft_data) // len(fft_data)
print(fa_data)
data_list.pop(0)
data_list.append(fa_data)
if fa_data > 1000:
self.start_luyin = True
if self.start_luyin:
kkk = lambda x: float(x) < 900
if all([kkk(i) for i in data_list]):
self.break_luyin = True
frames = frames[:-55]
if self.start_luyin:
frames.append(data)
print("* 录音结束")
stream.stop_stream()
stream.close()
p.terminate()
if os.path.exists(WAVE_OUTPUT_FILENAME):
os.remove(WAVE_OUTPUT_FILENAME)
with wave.open(WAVE_OUTPUT_FILENAME, 'wb') as wf:
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
if __name__ == '__main__':
c=record()
c.recording()
\ No newline at end of file
import wave
import websocket
import datetime
import hashlib
import base64
import hmac
import json
from urllib.parse import urlencode
import time
import ssl
from wsgiref.handlers import format_date_time
from datetime import datetime
from time import mktime
import _thread as thread
import os
from xpinyin import Pinyin
from playsound import playsound
STATUS_FIRST_FRAME = 0 # 第一帧的标识
STATUS_CONTINUE_FRAME = 1 # 中间帧标识
STATUS_LAST_FRAME = 2 # 最后一帧的标识
class Ws_Param(object):
# 初始化
def __init__(self, APPID, APIKey, APISecret, Text):
self.APPID = APPID
self.APIKey = APIKey
self.APISecret = APISecret
self.Text = Text
# 公共参数(common)
self.CommonArgs = {"app_id": self.APPID}
# 业务参数(business),更多个性化参数可在官网查看
# self.BusinessArgs = {"aue": "lame","sfl":1, "auf": "audio/L16;rate=16000", "vcn": "xiaoyan", "tte": "utf8", "speed": 20,"volume":100}
self.Data = {"status": 2, "text": str(base64.b64encode(self.Text.encode('utf-8')), "UTF8")}
#使用小语种须使用以下方式,此处的unicode指的是 utf16小端的编码方式,即"UTF-16LE"”
#self.Data = {"status": 2, "text": str(base64.b64encode(self.Text.encode('utf-16')), "UTF8")}
def set_BusinessArgs(self,vcn,volume):
self.BusinessArgs={"aue": "lame","sfl":1, "auf": "audio/L16;rate=16000", "vcn": vcn, "tte": "utf8", "speed": 50,"volume":volume}
# 生成url
def create_url(self):
url = 'wss://tts-api.xfyun.cn/v2/tts'
# 生成RFC1123格式的时间戳
now = datetime.now()
date = format_date_time(mktime(now.timetuple()))
# 拼接字符串
signature_origin = "host: " + "ws-api.xfyun.cn" + "\n"
signature_origin += "date: " + date + "\n"
signature_origin += "GET " + "/v2/tts " + "HTTP/1.1"
# 进行hmac-sha256进行加密
signature_sha = hmac.new(self.APISecret.encode('utf-8'), signature_origin.encode('utf-8'),
digestmod=hashlib.sha256).digest()
signature_sha = base64.b64encode(signature_sha).decode(encoding='utf-8')
authorization_origin = "api_key=\"%s\", algorithm=\"%s\", headers=\"%s\", signature=\"%s\"" % (
self.APIKey, "hmac-sha256", "host date request-line", signature_sha)
authorization = base64.b64encode(authorization_origin.encode('utf-8')).decode(encoding='utf-8')
# 将请求的鉴权参数组合为字典
v = {
"authorization": authorization,
"date": date,
"host": "ws-api.xfyun.cn"
}
# 拼接鉴权参数,生成url
url = url + '?' + urlencode(v)
# print("date: ",date)
# print("v: ",v)
# 此处打印出建立连接时候的url,参考本demo的时候可取消上方打印的注释,比对相同参数时生成的url与自己代码生成的url是否一致
# print('websocket url :', url)
return url
def on_message(ws, message):
try:
message =json.loads(message)
code = message["code"]
sid = message["sid"]
audio = message["data"]["audio"]
audio = base64.b64decode(audio)
status = message["data"]["status"]
print(message)
if status == 2:
print("ws is closed")
ws.close()
if code != 0:
errMsg = message["message"]
print("sid:%s call error:%s code is:%s" % (sid, errMsg, code))
else:
with open('./text.mp3', 'ab') as f:
f.write(audio)
except Exception as e:
print("receive msg,but parse exception:", e)
# 收到websocket错误的处理
def on_error(ws, error):
print("### error:", error)
# 收到websocket关闭的处理
def on_close(ws):
print("### closed ###")
# 收到websocket连接建立的处理
def on_open(ws):
def run(*args):
d = {"common": wsParam.CommonArgs,
"business": wsParam.BusinessArgs,
"data": wsParam.Data,
}
d = json.dumps(d)
print("------>开始发送文本数据")
ws.send(d)
if os.path.exists('./text.mp3'):
os.remove('./text.mp3')
thread.start_new_thread(run, ())
def skip_video(self,text,vcn,volume):
# 测试时候在此处正确填写相关信息即可运行
global wsParam
self.set_BusinessArgs(self,vcn,volume)
wsParam = Ws_Param(APPID='5d1ad3d5', APISecret='28c7560f3d6ec49f8c8750b76002ab34',
APIKey='b7c216ce0834468cc372f3f00d2d7b36',
Text=text)
websocket.enableTrace(False)
wsUrl = wsParam.create_url()
ws = websocket.WebSocketApp(wsUrl, on_message=Ws_Param.on_message, on_error=Ws_Param.on_error, on_close=Ws_Param.on_close)
ws.on_open =Ws_Param.on_open
ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})
print("转换完成")
def pcm2wav(self,pcm_file, wav_file, channels=1, bits=16, sample_rate=16000):
pcmf = open(pcm_file, 'rb')
pcmdata = pcmf.read()
pcmf.close()
if bits % 8 != 0:
raise ValueError("bits % 8 must == 0. now bits:" + str(bits))
wavfile = wave.open(wav_file, 'wb')
wavfile.setnchannels(channels)
wavfile.setsampwidth(bits // 8)
wavfile.setframerate(sample_rate)
wavfile.writeframes(pcmdata)
wavfile.close()
if __name__ == '__main__':
# A=Ws_Param(APPID='5d1ad3d5', APISecret='28c7560f3d6ec49f8c8750b76002ab34',
# APIKey='b7c216ce0834468cc372f3f00d2d7b36',Text="")
Ws_Param.skip_video(self= Ws_Param,text='小艺小艺',vcn="kaiselin",volume=100)
p=Pinyin()
print(p.get_pinyin("小菊",""))
# A.pcm2wav('nnn.pcm',"nnn.wav")
playsound("text.mp3")
# play_mp3('nn.wav')
\ No newline at end of file
......@@ -2,6 +2,8 @@
import os
import sys
import pathlib
import re
import cv2
import numpy as np
import difflib
......@@ -159,6 +161,7 @@ class run():
#根据概率值执行过滤
self.words= run.text_filter(out)
#不过滤
# self.words = out[0][0]
#如果有识别结果且未被过滤
......@@ -179,8 +182,14 @@ class run():
def get_equal_rate_1(str1, str2):
return difflib.SequenceMatcher(None, str1, str2).quick_ratio()
#更正识别出错的文字
def correct(string,errorWord,rightWord):
if re.search(errorWord,string):
string=string.replace(errorWord,rightWord)
return string
if __name__ == '__main__':
ru=run()
ru.ocr_video(1)
print(ru.words)
# ru=run()
# ru.ocr_video(1)
# print(ru.words)
# name=ru.ocr_video(0)
print(correct("我想看甄传",'甄媛传','甄嬛传'))
\ No newline at end of file
......@@ -189,6 +189,8 @@ class run():
# self.words= run.text_filter(out)
# 不过滤
self.words = out[0][0]
# 替换识别出错的甄嬛传
self.words=correct(self.words,"甄媛传",'甄嬛传')
#根据相似度取相似度结果最高的
similarity =get_equal_rate_1(self.words,text)
similarity1 = get_equal_rate_1(self.final_text,text)
......@@ -258,7 +260,11 @@ def delet_fuhao(words):
tuple1.append(n)
new_text = "".join(tuple1)
return new_text
#更正识别出错的文字
def correct(string,errorWord,rightWord):
if re.search(errorWord,string):
string=string.replace(errorWord,rightWord)
return string
# if __name__ == '__main__':
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment