【无标题】单图片识别

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')







  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值