AI-powered OCR service for images and PDF documents using iFlytek's advanced recognition APIs.
bash
# OCR an image and extract text
python3 scripts/image_ocr.py /path/to/image.jpg
# Save result to file
python3 scripts/image_ocr.py /path/to/image.jpg -o output.txt
# Specify output format
python3 scripts/image_ocr.py /path/to/image.jpg --format json
python3 scripts/image_ocr.py /path/to/image.jpg --format markdown
bash
# Convert PDF to Word (default)
python3 scripts/pdf_ocr.py document.pdf
# Convert PDF to Markdown
python3 scripts/pdf_ocr.py document.pdf --format markdown
# Convert PDF to JSON
python3 scripts/pdf_ocr.py document.pdf --format json
# From public URL
python3 scripts/pdf_ocr.py --pdf-url "https://example.com/doc.pdf" --format word
Get credentials from iFlytek Open Platform:
For Image OCR:
For PDF OCR:
bash
# Required for both Image OCR and PDF OCR
export IFLY_APP_ID="your_app_id"
# Required for Image OCR
export IFLY_API_KEY="your_api_key"
# Required for PDF OCR
export IFLY_API_SECRET="your_api_secret"
AI-powered OCR: Advanced AI model for accurate text extraction
Multiple output formats:
Large PDF support: Up to 100 pages per document
Page-by-page results: Access individual page results
Download URLs: Direct links to processed files
ParameterTypeRequiredDescriptionimage_pathstringYesPath to image file--formatstringNoOutput format: json, markdown, json,markdown (default: json,markdown)--outputstringNoSave result to file
ParameterTypeRequiredDescriptionpdf_pathstringYes*Path to PDF file--pdf-urlstringNo*Public URL of PDF file--formatstringNoOutput format: word, markdown, json (default: word)--no-pollflagNoReturn task ID without polling--poll-intervalintNoPolling interval in seconds (min 5, default: 5)--max-waitintNoMaximum wait time in seconds (default: 300)
*Either pdf_path or --pdf-url must be provided
Uses HMAC-SHA256 signature authentication:
EEE, dd MMM yyyy HH:mm:ss GMThost: {host}\\ndate: {date}\\nPOST {path} HTTP/1.1HMAC-SHA256(signature_origin, apiSecret)hmac username="{apiKey}", algorithm="hmac-sha256", headers="host date request-line", signature="{signature}"?authorization={auth}&host={host}&date={date}Uses MD5 + HMAC-SHA1 signature authentication:
auth = MD5(appId + timestamp)signature = Base64(HMAC-SHA1(auth, apiSecret))appId: Application IDtimestamp: Timestamp in secondssignature: Generated signatureImportant: Timestamp must be within 5 minutes of server time.
json
{
"header": {
"code": 0,
"message": "success"
},
"payload": {
"result": {
"text": "Base64-encoded OCR text..."
}
}
}
json
{
"flag": true,
"code": 0,
"desc": "成功",
"data": {
"taskNo": "25082744936879",
"status": "CREATE",
"tip": "任务创建成功"
}
}
json
{
"flag": true,
"code": 0,
"desc": "成功",
"data": {
"taskNo": "25082759289333",
"exportFormat": "word",
"status": "FINISH",
"downUrl": "http://bjcdn.openstorage.cn/...",
"tip": "已完成",
"pageList": [...]
}
}
StatusDescriptionCREATETask created successfullyWAITINGWaiting in queueDOINGProcessingFINISHCompletedFAILEDFailedANY_FAILEDPartially completed (some pages failed)STOPPaused
(。・ω・。) 嗨遇到错误码了吗?来看看怎么解决吧 ✧⁺⸜(●˙▾˙●)⸝⁺✧
CodeDescriptionHintSolution10009input invalid data(◎_◎;) 哎呀数据格式不太对呢检查输入数据是否符合要求10010service license not enough(╯°□°)╯︵ ┻━┻ 授权数量不足或已过期!提交工单联系客服10019service read buffer timeout(。-`ω´-) session超时啦检查是否数据发送完毕但未关闭连接10043Syscall AudioCodingDecode error(◎_◎;) 音频解码失败惹...检查aue参数,如果为speex,请确保音频是speex音频并分段压缩且与帧大小一致10114session timeout(。-`ω´-) 会话时间超时啦检查是否发送数据时间超过了60s10139invalid param(◎_◎;) 参数好像不太对呢检查参数是否正确10160parse request json error(◎_◎;) 请求数据格式有误检查请求数据是否是合法的json10161parse base64 string error(◎_◎;) Base64解码失败啦检查发送的数据是否使用base64编码了10163param validate error(◎_◎;) 参数校验没通过呢具体原因见详细的描述10200read data timeout(。-`ω´-) 读取数据超时了检查是否累计10s未发送数据并且未关闭连接10222context deadline exceeded(╯°□°)╯︵ ┻━┻ 出错啦!1.检查上传数据是否超过接口上限;2.SSL证书无效请提交工单10223RemoteLB: can't find valued addr(◎_◎;) 找不到服务节点呢提交工单联系技术人员10313invalid appid(◎_◎;) appid和apikey不匹配哦检查appid是否合法10317invalid version(◎_◎;) 版本号有问题呢请到控制台提交工单联系技术人员10700not authority(╯°□°)╯︵ ┻━┻ 权限不足!按照报错原因对照开发文档检查,如仍无法解决,请提供sid及错误信息提交工单11200auth no license(╯°□°)╯︵ ┻━┻ 功能未授权!检查appid是否正确,确认是否添加了相关服务,检查调用量是否超限或授权是否到期11201auth no enough license(╯°□°)╯︵ ┻━┻ 每日交互次数超限啦!提交应用审核提额或联系商务购买企业级接口11503server error: atmos return error(。-`ω´-) 服务器返回了错误数据...提交工单11502server error: too many datas(。-`ω´-) 服务器配置有问题呢提交工单100001100010WrapperInitErr(◎_◎;) 引擎调用出错啦!请根据message中的errno查看引擎错误码说明
CodeDescriptionSolution10000System errorCheck auth info, request method, parameters10001Signature authentication failedCheck credentials10002Business processing errorCheck error message10003Quota/insufficient balanceCheck account balance
json,markdown to get both structured and formatted output-o flag to save OCR results to file