語音識別
# PinToo之訊飛語音轉文字
# 1. 說明
該範例使用智能手機上的PinToo程式,通過語音識別的方式將語音轉換為文字。通過這種方式可以把語音(≤60秒)轉換成對應的文字資訊,讓機器能夠「聽懂」人類語言,相當於給機器安裝上「耳朵」,使其具備「能聽」的功能。支援中、英語種的識別,還提供廣東話、河南話、四川話等方言的識別。使用該功能需要授予PinToo使用麥克風的相關許可權。
# 2. 設計明細
開啟PinToo設計器,分別加入下插圖之控制元件。或者點選左上角的[打開模板Lib檔案]
,選擇模板檔案來打開對應模板。
①:TfxSuperButton元件,控制元件名稱為fxSuperButton1
。
②:TfxMemo元件,控制元件名稱為fxMemo1
。
③:TfxXFVoiceIAT元件,控制元件名稱為fxXFVoiceIAT1
。
fxRunFrame屬性設定
Height
:設定頁面高度=800
。Width
:設定頁面寬度=400
。
①fxSuperButton1屬性設定
Height
:設定控制元件高度=200
。Width
:設定控制元件寬度=200
。ButtonType
:設定按鈕型別,設定為TfxSvgButton
。ButtonType.SvgData
:設定SVG數據,其數據內容如下。
<path d="M113.227279663086,64.7272720336914 C113.227279663086,66.9318161010742 115.431823730469,69.1363677978516 117.636367797852,69.1363677978516 L122.045455932617,69.1363677978516 L122.045455932617,77.9545516967773 L117.636367797852,77.9545516967773 C115.431823730469,77.9545516967773 113.227279663086,80.1590957641602 113.227279663086,82.3636474609375 C113.227279663086,84.5681915283203 115.431823730469,86.7727355957031 117.636367797852,86.7727355957031 L122.045455932617,86.7727355957031 L122.045455932617,91.1818237304688 C122.045455932617,103.527290344238 112.345458984375,113.227294921875 100,113.227294921875 C87.6545333862305,113.227294921875 77.9545440673828,103.527290344238 77.9545440673828,91.1818389892578 L77.9545440673828,86.7727432250977 L82.363639831543,86.7727432250977 C84.5681762695313,86.7727432250977 86.7727203369141,84.5681991577148 86.7727203369141,82.3636474609375 C86.7727203369141,80.1591033935547 84.5681915283203,77.9545593261719 82.363639831543,77.9545593261719 L77.9545440673828,77.9545593261719 L77.9545440673828,69.1363754272461 L82.363639831543,69.1363754272461 C84.5681762695313,69.1363754272461 86.7727203369141,66.9318313598633 86.7727203369141,64.7272872924805 C86.7727203369141,62.5227317810059 84.5681915283203,60.3181915283203 82.363639831543,60.3181915283203 L77.9545440673828,60.3181915283203 L77.9545440673828,55.9090957641602 C77.9545440673828,43.5636405944824 87.654541015625,33.8636436462402 100,33.8636436462402 C112.345458984375,33.8636436462402 122.045455932617,43.5636405944824 122.045455932617,55.9090957641602 L122.045455932617,60.3181915283203 L117.636367797852,60.3181915283203 C115.431823730469,60.3181915283203 113.227279663086,62.5227317810059 113.227279663086,64.7272872924805 Z" p-id="2870" fill="#FFD7FFDA" stroke="Null"></path> <path d="M188.18180847168,25.0454521179199 L188.18180847168,11.8181829452515 L174.954528808594,11.8181829452515 C172.749984741211,11.8181829452515 170.545440673828,9.61363792419434 170.545440673828,7.40909099578857 L29.4545478820801,7.40909099578857 C29.4545478820801,9.6136360168457 27.2500019073486,11.8181810379028 25.0454559326172,11.8181810379028 L11.8181829452515,11.8181810379028 L11.8181829452515,25.0454521179199 C11.8181829452515,27.2500019073486 9.61363792419434,29.4545440673828 7.40909099578857,29.4545440673828 L7.40909099578857,170.545440673828 C9.6136360168457,170.545440673828 11.8181810379028,172.749984741211 11.8181810379028,174.954528808594 L11.8181810379028,188.18180847168 L25.0454521179199,188.18180847168 C27.2500019073486,188.18180847168 29.4545440673828,190.386352539063 29.4545440673828,192.590896606445 L170.545440673828,192.590896606445 C170.545440673828,190.386352539063 172.749984741211,188.18180847168 174.954528808594,188.18180847168 L188.18180847168,188.18180847168 L188.18180847168,174.954528808594 C188.18180847168,172.749984741211 190.386352539063,170.545440673828 192.590896606445,170.545440673828 L192.590896606445,29.4545478820801 C190.386352539063,29.4545478820801 188.18180847168,27.2500019073486 188.18180847168,25.0454559326172 Z M69.1363525390625,55.9090957641602 C69.1363525390625,38.7136383056641 82.8045349121094,25.0454559326172 99.9999923706055,25.0454559326172 C117.195449829102,25.0454559326172 130.863632202148,38.7136383056641 130.863632202148,55.9090957641602 L130.863632202148,91.1818161010742 C130.863632202148,108.37727355957 117.195449829102,122.045463562012 99.9999923706055,122.045463562012 C82.8045272827148,122.045463562012 69.1363525390625,108.377288818359 69.1363525390625,91.1818237304688 L69.1363525390625,55.9091033935547 Z M104.40909576416,139.681823730469 L104.40909576416,166.136383056641 L117.636367797852,166.136383056641 C119.840911865234,166.136383056641 122.045455932617,168.340896606445 122.045455932617,170.545440673828 C122.045455932617,172.749984741211 119.840911865234,174.954528808594 117.636367797852,174.954528808594 L82.363639831543,174.954528808594 C80.1590957641602,174.954528808594 77.9545440673828,172.749984741211 77.9545440673828,170.545440673828 C77.9545440673828,168.340896606445 80.1590881347656,166.136383056641 82.363639831543,166.136383056641 L95.5909042358398,166.136383056641 L95.5909042358398,139.681823730469 C70.8999938964844,137.477279663086 51.4999961853027,118.518180847168 51.4999961853027,95.5909118652344 C51.4999961853027,93.3863677978516 53.7045402526855,91.1818161010742 55.9090881347656,91.1818161010742 C58.113639831543,91.1818161010742 60.3181838989258,93.386360168457 60.3181838989258,95.5909118652344 C60.3181838989258,114.990921020508 77.9545440673828,130.863632202148 100.000007629395,130.863632202148 C122.045463562012,130.863632202148 139.681823730469,114.990905761719 139.681823730469,95.5909042358398 C139.681823730469,93.386360168457 141.886367797852,91.1818084716797 144.090911865234,91.1818084716797 C146.295455932617,91.1818084716797 148.5,93.3863525390625 148.5,95.5909042358398 C148.5,118.518180847168 129.099990844727,137.477264404297 104.40909576416,139.681823730469 Z" p-id="2871" fill="#FFD7FFDA" stroke="Null"></path> <path d="M113.227279663086,64.7272720336914 C113.227279663086,66.9318161010742 115.431823730469,69.1363677978516 117.636367797852,69.1363677978516 L122.045455932617,69.1363677978516 L122.045455932617,77.9545516967773 L117.636367797852,77.9545516967773 C115.431823730469,77.9545516967773 113.227279663086,80.1590957641602 113.227279663086,82.3636474609375 C113.227279663086,84.5681915283203 115.431823730469,86.7727355957031 117.636367797852,86.7727355957031 L122.045455932617,86.7727355957031 L122.045455932617,91.1818237304688 C122.045455932617,103.527290344238 112.345458984375,113.227294921875 100,113.227294921875 C87.6545333862305,113.227294921875 77.9545440673828,103.527290344238 77.9545440673828,91.1818389892578 L77.9545440673828,86.7727432250977 L82.363639831543,86.7727432250977 C84.5681762695313,86.7727432250977 86.7727203369141,84.5681991577148 86.7727203369141,82.3636474609375 C86.7727203369141,80.1591033935547 84.5681915283203,77.9545593261719 82.363639831543,77.9545593261719 L77.9545440673828,77.9545593261719 L77.9545440673828,69.1363754272461 L82.363639831543,69.1363754272461 C84.5681762695313,69.1363754272461 86.7727203369141,66.9318313598633 86.7727203369141,64.7272872924805 C86.7727203369141,62.5227317810059 84.5681915283203,60.3181915283203 82.363639831543,60.3181915283203 L77.9545440673828,60.3181915283203 L77.9545440673828,55.9090957641602 C77.9545440673828,43.5636405944824 87.654541015625,33.8636436462402 100,33.8636436462402 C112.345458984375,33.8636436462402 122.045455932617,43.5636405944824 122.045455932617,55.9090957641602 L122.045455932617,60.3181915283203 L117.636367797852,60.3181915283203 C115.431823730469,60.3181915283203 113.227279663086,62.5227317810059 113.227279663086,64.7272872924805 Z" p-id="2872" fill="#FF60C0FF" stroke="Null"></path> <path d="M100.000007629395,25.0454521179199 C82.8045425415039,25.0454521179199 69.1363677978516,38.7136383056641 69.1363677978516,55.9090957641602 L69.1363677978516,91.1818161010742 C69.1363677978516,108.37727355957 82.8045501708984,122.045463562012 100.000007629395,122.045463562012 C117.195449829102,122.045463562012 130.863632202148,108.377288818359 130.863632202148,91.1818237304688 L130.863632202148,55.9091033935547 C130.863632202148,38.7136421203613 117.195465087891,25.0454635620117 100.000007629395,25.0454635620117 Z M122.045463562012,91.1818161010742 C122.045463562012,103.527290344238 112.345458984375,113.227279663086 100.000007629395,113.227279663086 C87.6545486450195,113.227279663086 77.9545516967773,103.527290344238 77.9545516967773,91.1818161010742 L77.9545516967773,86.7727203369141 L82.3636474609375,86.7727203369141 C84.5681915283203,86.7727203369141 86.7727355957031,84.5681915283203 86.7727355957031,82.363639831543 C86.7727355957031,80.1590881347656 84.5681915283203,77.9545440673828 82.3636474609375,77.9545440673828 L77.9545516967773,77.9545440673828 L77.9545516967773,69.136360168457 L82.3636474609375,69.136360168457 C84.5681915283203,69.136360168457 86.7727355957031,66.9318161010742 86.7727355957031,64.7272720336914 C86.7727355957031,62.5227203369141 84.5681915283203,60.3181762695313 82.3636474609375,60.3181762695313 L77.9545516967773,60.3181762695313 L77.9545516967773,55.9090843200684 C77.9545516967773,43.5636291503906 87.6545486450195,33.8636283874512 100.000007629395,33.8636283874512 C112.345458984375,33.8636283874512 122.045463562012,43.5636291503906 122.045463562012,55.9090843200684 L122.045463562012,60.3181762695313 L117.636383056641,60.3181762695313 C115.431838989258,60.3181762695313 113.227294921875,62.5227203369141 113.227294921875,64.7272720336914 C113.227294921875,66.9318161010742 115.431838989258,69.136360168457 117.636383056641,69.136360168457 L122.045463562012,69.136360168457 L122.045463562012,77.9545440673828 L117.636383056641,77.9545440673828 C115.431838989258,77.9545440673828 113.227294921875,80.1590881347656 113.227294921875,82.363639831543 C113.227294921875,84.5681915283203 115.431838989258,86.7727203369141 117.636383056641,86.7727203369141 L122.045463562012,86.7727203369141 L122.045463562012,91.1818161010742 Z" p-id="2873" fill="#FF1C2754" stroke="Null"></path> <path d="M104.40909576416,139.681823730469 L104.40909576416,166.136383056641 L117.636367797852,166.136383056641 C119.840911865234,166.136383056641 122.045455932617,168.340896606445 122.045455932617,170.545440673828 C122.045455932617,172.749984741211 119.840911865234,174.954528808594 117.636367797852,174.954528808594 L82.363639831543,174.954528808594 C80.1590957641602,174.954528808594 77.9545440673828,172.749984741211 77.9545440673828,170.545440673828 C77.9545440673828,168.340896606445 80.1590881347656,166.136383056641 82.363639831543,166.136383056641 L95.5909042358398,166.136383056641 L95.5909042358398,139.681823730469 C70.8999938964844,137.477279663086 51.4999961853027,118.518180847168 51.4999961853027,95.5909118652344 C51.4999961853027,93.3863677978516 53.7045402526855,91.1818161010742 55.9090881347656,91.1818161010742 C58.113639831543,91.1818161010742 60.3181838989258,93.386360168457 60.3181838989258,95.5909118652344 C60.3181838989258,114.990921020508 77.9545440673828,130.863632202148 100.000007629395,130.863632202148 C122.045463562012,130.863632202148 139.681823730469,114.990905761719 139.681823730469,95.5909042358398 C139.681823730469,93.386360168457 141.886367797852,91.1818084716797 144.090911865234,91.1818084716797 C146.295455932617,91.1818084716797 148.5,93.3863525390625 148.5,95.5909042358398 C148.5,118.518180847168 129.099990844727,137.477264404297 104.40909576416,139.681823730469 Z" p-id="2874" fill="#FF1C2754" stroke="Null"></path> <path d="M29.4545478820801,7.40909099578857 C29.4545478820801,9.6136360168457 27.2500019073486,11.8181810379028 25.0454559326172,11.8181810379028 L11.8181829452515,11.8181810379028 L11.8181829452515,25.0454521179199 C11.8181829452515,27.2500019073486 9.61363792419434,29.4545440673828 7.40909099578857,29.4545440673828 C5.20454406738281,29.4545440673828 3,27.2499980926514 3,25.0454521179199 L3,7.40909099578857 C3,5.20454597473145 5.20454597473145,3 7.40909099578857,3 L25.0454521179199,3 C27.2500019073486,3 29.4545440673828,5.20454597473145 29.4545440673828,7.40909099578857 Z M197.000015258789,7.40909099578857 L197.000015258789,25.0454521179199 C197.000015258789,27.2500019073486 194.795455932617,29.4545440673828 192.590911865234,29.4545440673828 C190.386367797852,29.4545440673828 188.181823730469,27.2499980926514 188.181823730469,25.0454521179199 L188.181823730469,11.8181829452515 L174.954544067383,11.8181829452515 C172.75,11.8181829452515 170.545471191406,9.61363792419434 170.545471191406,7.40909099578857 C170.545471191406,5.20454406738281 172.75,3 174.954544067383,3 L192.590911865234,3 C194.795455932617,3 197.000015258789,5.20454597473145 197.000015258789,7.40909099578857 Z" p-id="2875" fill="#FF096610" stroke="Null"></path> <path d="M197.000015258789,174.954528808594 L197.000015258789,192.590896606445 C197.000015258789,194.795440673828 194.795455932617,197 192.590911865234,197 L174.954544067383,197 C172.75,197 170.545471191406,194.795440673828 170.545471191406,192.590896606445 C170.545471191406,190.386352539063 172.75,188.18180847168 174.954544067383,188.18180847168 L188.181823730469,188.18180847168 L188.181823730469,174.954528808594 C188.181823730469,172.749984741211 190.386367797852,170.545440673828 192.590911865234,170.545440673828 C194.795455932617,170.545440673828 197.000015258789,172.749984741211 197.000015258789,174.954528808594 Z" p-id="2876" fill="#FF096610" stroke="Null"></path> <path d="M29.4545478820801,192.590911865234 C29.4545478820801,194.795455932617 27.2500019073486,197.000015258789 25.0454559326172,197.000015258789 L7.40909099578857,197.000015258789 C5.20454597473145,197.000015258789 3,194.795455932617 3,192.590911865234 L3,174.954544067383 C3,172.75 5.20454597473145,170.545471191406 7.40909099578857,170.545471191406 C9.6136360168457,170.545471191406 11.8181810379028,172.75 11.8181810379028,174.954544067383 L11.8181810379028,188.181823730469 L25.0454521179199,188.181823730469 C27.2500019073486,188.181823730469 29.4545440673828,190.386367797852 29.4545440673828,192.590911865234 Z" p-id="2877" fill="#FF096610" stroke="Null"></path>
1
2
3
4
5
6
7
8②fxMemo1屬性設定
Height
:設定控制元件高度=295
。Width
:設定控制元件寬度=360
。Opacity
:設定控制元件透明度=0.9
。
# 3. 程式設計
點選程式設計界面右下角的按鈕,切換至單元選擇界面,勾選需要使用的單元。該程式需要引用 XFVoice
單元。
# 3.1. 程式初始設定
該程式無初始設定。
# 3.2. 事件設定
- ①fxSuperButton1-OnClick事件
點選語音識別按鈕,打開語音識別的界面進行語音識別輸入。
Procedure fxSuperButton1OnClick(Sender: TObject);
Begin
fxXFVoiceIAT1.IAT_StartListening(nil);
End;
1
2
3
4
2
3
4
- ③fxXFVoiceIAT1-OnRecognizerResult事件
當語音識別獲取到結果時,將識別結果回傳至文字框中,輸出識別結果。
Procedure fxXFVoiceIAT1OnRecognizerResult(Sender: TObject; AResult: string);
Begin
fxMemo1.Lines.Add('識別結果:' + AResult);
End;
1
2
3
4
2
3
4
# 4. 運行結果
使用滑鼠在 PinToo 功能表,點選[儲存至資料庫]
按鈕,將其儲存至資料庫,點選[除錯運行]
確認能夠正常打開。
通過同步中心,將程式上傳至手機PinToo運行;同步時,請確保手機已經運行PinToo,並且已經登陸。
點選識別按鈕,彈出視窗提示輸入語音,可對準手機麥克風進行說話測試,說話完成後,語音識別完成並輸出識別的結果。