from aip import AipOcr
from aip import AipSpeech
import os
# 定义常量
# 新建图像识别客户端
APP_ID = '73549357'
API_KEY = 'LlrPOIW0YXnbsNaZgq9gFAHP'
SECRET_KEY = 'ANQdsbdOh1epvZyuiO3tyRkTJyJaEggs'
import time
time.sleep(1) # 防止解析速度过快,无法响应
# 初始化AipFace对象
aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY)
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
# 读取图片
filePath = "1.jpg"
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
# 调用OCR识别车牌
image_content = get_file_content(filePath)
if image_content is None:
exit() # 如果文件未找到,则退出程序
options = {}
result = aipOcr.vehicleLicense(get_file_content(filePath), options)
if 'error_code' in result:
print(f"OCR识别错误:{result['error_msg']}")
else:
with open('output.txt', 'w', encoding='utf-8') as file:
detail=''
for key ,value in result['words_result'].items():
detail += f"{key}:{value['words']}\n"
file.write(detail)
print(detail,end = '')
text_to_speech = detail.strip()
result1 = client.synthesis(detail, 'zh', 1, {
'vol': 5,'per':5118
})
# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result1, dict):
with open('audio.mp3', 'wb') as f:
f.write(result1)
os.system('audio.mp3')
【无标题】单图片识别
最新推荐文章于 2024-07-28 15:46:11 发布