HrpSimpleTester
本文介绍如何运行文件语音识别库Hrp
的样例程序(HrpSimpleTester
)。HrpSimpleTester
在控制台上运行,可以将音频文件转录为文本。
备注
- 运行时需要设置在个人页面上显示的
APPKEY
警告
- 请注意,使用语音识别会产生相应的费用
准备
按照获取方法获取源代码。将其放置在本地机器的任意目录中。
命令行接口
Usage: HrpSimpleTester <url> <audioFileName> <codec> <grammarFileNames> [<authorization>]
参数
参数 | 说明 |
---|---|
url | Endpoint |
audioFileName | 音频文件路径 |
codec | 解码器 |
grammarFileNames | 语法文件名 |
authorization | APPKEY |
运行示例
每种编程语言的目录中都有run.sh
或run.bat
文件。通过执行这些文件,可以使用以下参数运行样例程序。
参数 | 值 | 说明 |
---|---|---|
url | https://acp-api.amivoice.com/v1/recognize | 保存日志的HTTP接口 endpoint |
audioFileName | ../../audio/test.wav | 样例程序附带的音频文件 |
codec | 16K | 音频格式 |
grammarFileNames | -a-general | 会話_汎用引擎的连接引擎名 |
authorization | APPKEY | 请指定个人页面上显示的 APPKEY |
执行run
脚本
Windows系统
双击各<编程语言>文件夹下的 run.bat 文件,可以将该文件夹作为当前目录执行。执行后,会提示输入 APPKEY。
如果从终端执行,请将 Hrp/<编程语言>
设为当前目录,然后执行以下命令:
run.bat
Linux系统
执行时,请将 Hrp/<编程语言>
设为当前目录。
chmod +x run.sh
./run.sh
输入APPKEY
执行后会提示输入APPKEY,请输入个人页面上显示的 APPKEY
或获取的一次性APPKEY。
Please enter AppKey:
执行结果
会显示每种编程语言的run脚本处理过程。以下是Python的示例:
+ export PYTHONPATH=src
+ PYTHONPATH=src
+ export SSL_CERT_FILE=../../curl-ca-bundle.crt
+ SSL_CERT_FILE=../../curl-ca-bundle.crt
+ python HrpSimpleTester.py https://acp-api.amivoice.com/v1/recognize ../../audio/test.wav 16K -a-general {APPKEY}
等待几秒后,无论使用哪种编程语言,都会得到类似以下的结果:
{"results":[{"tokens":[{"written":"\u30a2\u30c9\u30d0\u30f3\u30b9\u30c8\u30fb\u30e1\u30c7\u30a3\u30a2","confidence":1.00,"starttime":506,"endtime":1578,"spoken":"\u3042\u3069\u3070\u3093\u3059\u3068\u3081\u3067\u3043\u3042"},{"written":"\u306f","confidence":1.00,"starttime":1578,"endtime":1930,"spoken":"\u306f"},{"written":"\u3001","confidence":0.35,"starttime":1930,"endtime":2026,"spoken":"_"},{"written":"\u4eba","confidence":0.82,"starttime":2026,"endtime":2314,"spoken":"\u3072\u3068"},{"written":"\u3068","confidence":1.00,"starttime":2314,"endtime":2426,"spoken":"\u3068"},{"written":"\u6a5f\u68b0","confidence":1.00,"starttime":2426,"endtime":2826,"spoken":"\u304d\u304b\u3044"},{"written":"\u3068","confidence":1.00,"starttime":2826,"endtime":2938,"spoken":"\u3068"},{"written":"\u306e","confidence":0.97,"starttime":2938,"endtime":3082,"spoken":"\u306e"},{"written":"\u81ea\u7136","confidence":1.00,"starttime":3082,"endtime":3434,"spoken":"\u3057\u305c\u3093"},{"written":"\u306a","confidence":1.00,"starttime":3434,"endtime":3530,"spoken":"\u306a"},{"written":"\u30b3\u30df\u30e5\u30cb\u30b1\u30fc\u30b7\u30e7\u30f3","confidence":1.00,"starttime":3530,"endtime":4362,"spoken":"\u3053\u307f\u3085\u306b\u3051\u30fc\u3057\u3087\u3093"},{"written":"\u3092","confidence":1.00,"starttime":4362,"endtime":4442,"spoken":"\u3092"},{"written":"\u5b9f\u73fe","confidence":1.00,"starttime":4442,"endtime":4922,"spoken":"\u3058\u3064\u3052\u3093"},{"written":"\u3057","confidence":1.00,"starttime":4922,"endtime":5306,"spoken":"\u3057"},{"written":"\u3001","confidence":0.63,"starttime":5306,"endtime":5626,"spoken":"_"},{"written":"\u8c4a\u304b","confidence":1.00,"starttime":5626,"endtime":5994,"spoken":"\u3086\u305f\u304b"},{"written":"\u306a","confidence":1.00,"starttime":5994,"endtime":6090,"spoken":"\u306a"},{"written":"\u672a\u6765","confidence":1.00,"starttime":6090,"endtime":6490,"spoken":"\u307f\u3089\u3044"},{"written":"\u3092","confidence":1.00,"starttime":6490,"endtime":6570,"spoken":"\u3092"},{"written":"\u5275\u9020","confidence":0.96,"starttime":6570,"endtime":7050,"spoken":"\u305d\u3046\u305e\u3046"},{"written":"\u3057\u3066","confidence":1.00,"starttime":7050,"endtime":7226,"spoken":"\u3057\u3066"},{"written":"\u3044\u304f","confidence":1.00,"starttime":7226,"endtime":7418,"spoken":"\u3044\u304f"},{"written":"\u3053\u3068","confidence":0.96,"starttime":7418,"endtime":7674,"spoken":"\u3053\u3068"},{"written":"\u3092","confidence":1.00,"starttime":7674,"endtime":7722,"spoken":"\u3092"},{"written":"\u76ee\u6307\u3057","confidence":0.78,"starttime":7722,"endtime":8090,"spoken":"\u3081\u3056\u3057"},{"written":"\u307e\u3059","confidence":0.79,"starttime":8090,"endtime":8538,"spoken":"\u307e\u3059"},{"written":"\u3002","confidence":0.94,"starttime":8538,"endtime":8746,"spoken":"_"}],"confidence":0.981,"starttime":250,"endtime":8746,"tags":[],"rulename":"","text":"\u30a2\u30c9\u30d0\u30f3\u30b9\u30c8\u30fb\u30e1\u30c7\u30a3\u30a2\u306f\u3001\u4eba\u3068\u6a5f\u68b0\u3068\u306e\u81ea\u7136\u306a\u30b3\u30df\u30e5\u30cb\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u73fe\u3057\u3001\u8c4a\u304b\u306a\u672a\u6765\u3092\u5275\u9020\u3057\u3066\u3044\u304f\u3053\u3068\u3092\u76ee\u6307\u3057\u307e\u3059\u3002"}],"utteranceid":"20240720/10/0190cdc4655b0a30300594c8_20240720_103158","text":"\u30a2\u30c9\u30d0\u30f3\u30b9\u30c8\u30fb\u30e1\u30c7\u30a3\u30a2\u306f\u3001\u4eba\u3068\u6a5f\u68b0\u3068\u306e\u81ea\u7136\u306a\u30b3\u30df\u30e5\u30cb\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u73fe\u3057\u3001\u8c4a\u304b\u306a\u672a\u6765\u3092\u5275\u9020\u3057\u3066\u3044\u304f\u3053\u3068\u3092\u76ee\u6307\u3057\u307e\u3059\u3002","code":"","message":""}
-> アドバンスト・メディアは、人と機械との自然なコミュニケーションを実現し、豊かな未来を創造していくことを目指します。
第一行是API的原始响应,采用JSON格式。第二行"->"后面是text
字段中语音识别结果的文本输出。关于结果的处理,请参考语音识别结果格式。