語音播報
# PinToo之訊飛文字轉語音
# 1. 說明
該範例使用智能手機上的PinToo程式,通過TTS語音引擎將文字轉換成語音進行輸出。該功能將文字轉化為自然流暢的人聲,支援多語種、多方言和中英混合,廣泛應用於新聞閱讀、出行導航、智能硬體和通知播報等場景。使用該功能需要授予PinToo使用相關功能許可權。
# 2. 設計明細
開啟PinToo設計器,分別加入下插圖之控制元件。或者點選左上角的[打開模板Lib檔案]
,選擇模板檔案來打開對應模板。
①:TfxMemo元件,控制元件名稱為fxMemo1
。
②:TfxSuperButton元件,控制元件名稱為fxSuperButton1
。
③:TfxXFVoiceTTS元件,控制元件名稱為fxXFVoiceTTS1
。
①fxMemo1屬性設定
Height
:設定控制元件高度=295
。Width
:設定控制元件寬度=360
。Opacity
:設定控制元件透明度=0.9
。Lines
:設定文字編輯框中的內容,雙擊該屬性或者點選屬性右側的[...]
打開編輯器框,輸入內容。內容可參考如下:
②fxSuperButton1屬性設定
Height
:設定控制元件高度=200
。Width
:設定控制元件寬度=200
。ButtonType
:設定按鈕型別,設定為TfxSvgButton
。ButtonType.SvgData
:設定SVG數據,其數據內容如下。
<path d="M196.039443969727,100.000007629395 C197.000015258789,159.633224487305 159.613998413086,196.980804443359 99.9807968139648,196.058654785156 C40.3475952148438,196.980804443359 3,159.633224487305 3.92216110229492,100.000007629395 C3.00000143051147,40.3668098449707 40.347599029541,3.01921081542969 99.9807968139648,3.94137382507324 C159.613998413086,3.01921081542969 196.96159362793,40.3668098449707 196.039443969727,100.000007629395 Z" p-id="3859" fill="#FFFF866E" stroke="Null"></path> <path d="M195.770477294922,110.259078979492 C192.850280761719,67.801155090332 163.840560913086,41.6732063293457 119.192535400391,42.3648300170898 C71.5090179443359,41.5963592529297 41.5771522521973,71.5282287597656 42.3456192016602,119.21174621582 C41.6155738830566,163.859802246094 67.7819442749023,192.869506835938 110.201438903809,195.789688110352 C160.497741699219,192.715805053711 192.696578979492,160.516967773438 195.770477294922,110.259078979492 Z" p-id="3860" fill="#FFFF7F61" stroke="Null"></path> <path d="M194.464065551758,122.131927490234 C188.892669677734,96.1576614379883 168.374542236328,80.3271942138672 138.404266357422,80.7882843017578 C102.632019042969,80.2119216918945 80.1927261352539,102.651237487793 80.7690734863281,138.423461914063 C80.307991027832,168.393753051758 96.1384582519531,188.911880493164 122.074287414551,194.483276367188 C161.688888549805,188.028137207031 188.008926391602,161.708068847656 194.464065551758,122.131927490234 Z" p-id="3861" fill="#FFFF734D" stroke="Null"></path> <path d="M191.121231079102,136.348602294922 C184.935028076172,125.282638549805 173.177474975586,118.981201171875 157.615982055664,119.211738586426 C133.755020141602,118.827491760254 118.808280944824,133.774230957031 119.192535400391,157.635177612305 C118.923568725586,173.196685791016 125.263450622559,184.954254150391 136.290954589844,191.140426635742 C162.695510864258,183.387954711914 183.350250244141,162.747680664063 191.12126159668,136.348602294922 Z" p-id="3862" fill="#FFFF6A36" stroke="Null"></path> <path d="M94.2172775268555,42.3648300170898 M99.9807968139648,42.3648300170898 L99.9807968139648,42.3648300170898 C103.823165893555,42.3648300170898 105.744316101074,44.2859992980957 105.744316101074,48.128345489502 L105.744316101074,151.871658325195 C105.744316101074,155.714004516602 103.823165893555,157.635177612305 99.9808197021484,157.635177612305 L99.9808197021484,157.635177612305 C96.1384582519531,157.635177612305 94.21728515625,155.714004516602 94.21728515625,151.871658325195 L94.21728515625,48.1283416748047 C94.21728515625,44.2859992980957 96.1384582519531,42.3648262023926 99.9808197021484,42.3648262023926 Z" p-id="3863" fill="White" stroke="Null"></path> <path d="M67.3208618164063,61.5765495300293 M73.0843811035156,61.5765495300293 L73.0843811035156,61.5765495300293 C76.9267272949219,61.5765495300293 78.847900390625,63.4977226257324 78.847900390625,67.3400726318359 L78.847900390625,132.659942626953 C78.847900390625,136.502288818359 76.9267272949219,138.423461914063 73.0843811035156,138.423461914063 L73.0843811035156,138.423461914063 C69.2420349121094,138.423461914063 67.3208618164063,136.502288818359 67.3208618164063,132.659942626953 L67.3208618164063,67.3400726318359 C67.3208618164063,63.4977226257324 69.2420349121094,61.5765495300293 73.0843811035156,61.5765495300293 Z" p-id="3864" fill="White" stroke="Null"></path> <path d="M121.113700866699,61.5765495300293 M126.877227783203,61.5765495300293 L126.877227783203,61.5765495300293 C130.719573974609,61.5765495300293 132.640731811523,63.4977226257324 132.640731811523,67.3400726318359 L132.640731811523,132.659942626953 C132.640731811523,136.502288818359 130.719573974609,138.423461914063 126.877227783203,138.423461914063 L126.877227783203,138.423461914063 C123.034881591797,138.423461914063 121.113700866699,136.502288818359 121.113700866699,132.659942626953 L121.113700866699,67.3400726318359 C121.113700866699,63.4977226257324 123.034881591797,61.5765495300293 126.877227783203,61.5765495300293 Z" p-id="3865" fill="White" stroke="Null"></path> <path d="M148.010101318359,80.7882843017578 M153.773635864258,80.7882843017578 L153.773635864258,80.7882843017578 C157.615982055664,80.7882843017578 159.537139892578,82.7094573974609 159.537139892578,86.5518035888672 L159.537139892578,113.448226928711 C159.537139892578,117.290573120117 157.615982055664,119.21174621582 153.773635864258,119.21174621582 L153.773635864258,119.21174621582 C149.931289672852,119.21174621582 148.010101318359,117.290573120117 148.010101318359,113.448226928711 L148.010101318359,86.5518035888672 C148.010101318359,82.7094573974609 149.931289672852,80.7882843017578 153.773635864258,80.7882843017578 Z" p-id="3866" fill="White" stroke="Null"></path> <path d="M40.424446105957,80.7882843017578 M46.1879615783691,80.7882843017578 L46.1879615783691,80.7882843017578 C50.0303077697754,80.7882843017578 51.9514846801758,82.7094573974609 51.9514846801758,86.5518035888672 L51.9514846801758,113.448226928711 C51.9514846801758,117.290573120117 50.0303077697754,119.21174621582 46.1879615783691,119.21174621582 L46.1879615783691,119.21174621582 C42.3456192016602,119.21174621582 40.424446105957,117.290573120117 40.424446105957,113.448226928711 L40.424446105957,86.5518035888672 C40.424446105957,82.7094573974609 42.3456192016602,80.7882843017578 46.1879615783691,80.7882843017578 Z" p-id="3867" fill="White" stroke="Null"></path>
1
2
3
4
5
6
7
8
9
# 3. 程式設計
點選程式設計界面右下角的按鈕,切換至單元選擇界面,勾選需要使用的單元。該程式需要引用 XFVoice
單元。
# 3.1. 程式初始設定
程式啟動時,設定發聲的語音型別。
{
XFVoice_Voicer_xiaoyan = 'xiaoyan'; // 小燕 青年女聲 中英文(普通話) 預設
XFVoice_Voicer_xiaoyu = 'xiaoyu'; // 小宇 青年男聲 中英文(普通話)
XFVoice_Voicer_catherine = 'catherine'; // 凱瑟琳 青年女聲 英文
XFVoice_Voicer_henry = 'henry'; // 亨利 青年男聲 英文
XFVoice_Voicer_vimary = 'vimary'; // 瑪麗 青年女聲 英文
XFVoice_Voicer_vixy = 'vixy'; // 小研 青年女聲 中英文(普通話)
XFVoice_Voicer_xiaoqi = 'xiaoqi'; // 小琪 青年女聲 中英文(普通話)
XFVoice_Voicer_vixf = 'vixf'; // 小峰 青年男聲 中英文(普通話)
XFVoice_Voicer_xiaomei = 'xiaomei'; // 小梅 青年女聲 中英文(粵語)
XFVoice_Voicer_vixl = 'vixl'; // 小莉 青年女聲 中英文(臺灣普通話)
XFVoice_Voicer_xiaolin = 'xiaolin'; // 曉琳 青年女聲 中英文(臺灣普通話
XFVoice_Voicer_xiaorong = 'xiaorong'; // 小蓉 青年女聲 漢語(四川話)
XFVoice_Voicer_vixyun = 'vixyun'; // 小蕓 青年女聲 漢語(東北話)
XFVoice_Voicer_xiaoqian = 'xiaoqian'; // 小倩 青年女聲 漢語(東北話)
XFVoice_Voicer_xiaokun = 'xiaokun'; // 小坤 青年男聲 漢語(河南話)
XFVoice_Voicer_xiaoqiang = 'xiaoqiang'; // 小強 青年男聲 漢語(湖南話)
XFVoice_Voicer_vixying = 'vixying'; // 小瑩 青年女聲 漢語(陜西話)
XFVoice_Voicer_xiaoxin = 'xiaoxin'; // 小新 童年男聲 漢語(普通話)
XFVoice_Voicer_nannan = 'nannan'; // 楠楠 童年女聲 漢語(普通話)
XFVoice_Voicer_vils = 'vils'; // 老孫 老年男聲 漢語(普通話)
XFVoice_Voicer_Mariane = 'Mariane'; // Mariane 法語
XFVoice_Voicer_Allabent = 'Allabent'; // Allabent 俄語
XFVoice_Voicer_Gabriela = 'Gabriela'; // Gabriela 西班牙語
XFVoice_Voicer_Abha = 'Abha'; // Abha 印地語
XFVoice_Voicer_XiaoYun = 'XiaoYun'; // XiaoYun 越南語
}
Begin
fxXFVoiceTTS1.Voicer := 'vixy';
End.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 3.2. 事件設定
- ②fxSuperButton1-OnClick事件
點選語音按鈕時,將文字框中的內容轉換為語音發出。
Procedure fxSuperButton1OnClick(Sender: TObject);
Begin
fxXFVoiceTTS1.TTS_Play(fxMemo1.Lines.Text);
End;
1
2
3
4
2
3
4
# 4. 運行結果
使用滑鼠在 PinToo 功能表,點選[儲存至資料庫]
按鈕,將其儲存至資料庫,點選[除錯運行]
確認能夠正常打開。
通過同步中心,將程式上傳至手機PinToo運行;同步時,請確保手機已經運行PinToo,並且已經登陸。
點選語音輸出的按鈕,語音將會按照編輯框中的內容進行播放。