调用百度智能云API,【批量】实现身份证智能识别并转语音 | Python

前言

很早之前,写了一篇博客:【调用百度智能云API,实现身份证智能识别并转语音 | Python

最近,有同学说需要批量识别身份证信息,所以优化了一下代码。

批量识别,参考代码:

# -*- coding: utf-8 -*-
"""
Created on Mon May 29 16:29:43 2023 Sunny
"""
from aip import AipOcr,AipSpeech
 
clientAipOcr = AipOcr('23371074', 'POTXBZN7KLWfyCmrT53w3vlT', 'Fy0ykaHwKtL1pggSjp4m0dwfR68Gb6om')
clientAipSpeech = AipSpeech('23374670', 'znrQvqN4ZSqROVfmupthcieR', '2FYUADL7Nzj3foOWdoWguamGsTrSls5r')
 
""" 读取图片 """
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()
 
"""
    1.调用文字识别API识别图片上的文字
    2.拼接文字后调用语音合成API转换成语音
"""
 
def convert_picture_words(image, num):
    words=''
    wordsResult=clientAipOcr.basicGeneral(image)
    for item in wordsResult['words_result']:
        words+=item['words']+','
    if words=='':
        return
    words=words[:-1]
    print('words: ',words)
    speechResult=clientAipSpeech.synthesis(str(words), 'zh', 1, {
        'vol': 5,
        'per': 3
    })
    print('result: ',speechResult)
 
    # 识别正确返回语音二进制 错误则返回dict
    if not isinstance(speechResult, dict):
        file_name = 'result' + str(num) + '.mp3'  # 定义语音文件名
        with open(file_name, 'wb') as f:
            f.write(speechResult)
            print('识别完成')
 
 
if __name__ == '__main__':
    # 首先,定义需要识别的身份证文件列表
    file_list = ['身份证照1.png', '身份证照2.png', '身份证照3.png']
    
    # 遍历进行文字识别和语音合成
    for i in range(len(file_list)):
        image = get_file_content(file_list[i])
        convert_picture_words(image, i)

如果觉得不错,请点个赞吧~】 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

破风_1874

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值