1
1
const apiConfig = {
2
- aivoice : {
3
- url : "https://api.pearktrue.cn/api/aivoice/" ,
4
- speakers : [
5
- "清萍微调" , "晓田微调" , "晓华" , "晓田" , "开放" , "菲菲" , "琳琳" , "艾希"
6
- ]
7
- } ,
8
2
aivoicenet : {
9
3
url : "https://api.pearktrue.cn/api/aivoicenet" ,
10
4
speakers : [
@@ -27,6 +21,22 @@ const apiConfig = {
27
21
"Sadie" , "Daniel" , "Jacob" , "Natalie" , "Tyler" , "Lily" , "Thomas" , "Harper" , "Henry" , "Naomi" ,
28
22
"Ethan" , "Emma" , "Ava" , "Lucas" , "Chloe" , "Caleb" , "Sofia" , "Gabriel" , "Ivy"
29
23
]
24
+ } ,
25
+ leftsite : {
26
+ url : "https://t.leftsite.cn/tts" ,
27
+ speakers : [
28
+ "zh-CN-XiaoxiaoMultilingualNeural" , "zh-CN-XiaoxiaoNeural" , "zh-CN-YunxiNeural" , "zh-CN-YunjianNeural" ,
29
+ "zh-CN-XiaoyiNeural" , "zh-CN-YunyangNeural" , "zh-CN-XiaochenNeural" , "zh-CN-XiaohanNeural" ,
30
+ "zh-CN-XiaomengNeural" , "zh-CN-XiaomoNeural" , "zh-CN-XiaoqiuNeural" , "zh-CN-XiaorouNeural" ,
31
+ "zh-CN-XiaoruiNeural" , "zh-CN-XiaoshuangNeural" , "zh-CN-XiaoyanNeural" , "zh-CN-XiaoyouNeural" ,
32
+ "zh-CN-XiaozhenNeural" , "zh-CN-YunfengNeural" , "zh-CN-YunhaoNeural" , "zh-CN-YunjieNeural" ,
33
+ "zh-CN-YunxiaNeural" , "zh-CN-YunyeNeural" , "zh-CN-YunzeNeural" , "zh-CN-YunfanMultilingualNeural" ,
34
+ "zh-CN-YunxiaoMultilingualNeural" , "zh-CN-guangxi-YunqiNeural" , "zh-CN-henan-YundengNeural" ,
35
+ "zh-CN-liaoning-XiaobeiNeural" , "zh-CN-liaoning-YunbiaoNeural" , "zh-CN-shaanxi-XiaoniNeural" ,
36
+ "zh-CN-shandong-YunxiangNeural" , "zh-CN-sichuan-YunxiNeural" , "zh-HK-HiuMaanNeural" ,
37
+ "zh-HK-WanLungNeural" , "zh-HK-HiuGaaiNeural" , "zh-TW-HsiaoChenNeural" , "zh-TW-YunJheNeural" ,
38
+ "zh-TW-HsiaoYuNeural"
39
+ ]
30
40
}
31
41
} ;
32
42
@@ -37,16 +47,19 @@ function updateSpeakerOptions(apiName) {
37
47
speakers . forEach ( speaker => {
38
48
speakerSelect . append ( new Option ( speaker , speaker ) ) ;
39
49
} ) ;
50
+
51
+ const showAdditionalParams = apiName === 'leftsite' ;
52
+ $ ( '#leftsiteParams' ) . toggle ( showAdditionalParams ) ;
40
53
}
41
54
42
55
$ ( document ) . ready ( function ( ) {
43
- // Update speaker options based on selected API
56
+ // 更新所选 API 的讲述人选项
44
57
$ ( '#api' ) . on ( 'change' , function ( ) {
45
58
updateSpeakerOptions ( this . value ) ;
46
59
} ) ;
47
60
48
- // Set initial speaker options
49
- updateSpeakerOptions ( 'aivoice ' ) ;
61
+ // 设置初始的讲述人选项
62
+ updateSpeakerOptions ( 'aivoicenet ' ) ;
50
63
51
64
$ ( '#text2voice-form' ) . on ( 'submit' , function ( event ) {
52
65
event . preventDefault ( ) ;
@@ -55,7 +68,18 @@ $(document).ready(function () {
55
68
const apiUrl = apiConfig [ apiName ] . url ;
56
69
const speaker = $ ( '#speaker' ) . val ( ) ;
57
70
const text = $ ( '#text' ) . val ( ) ;
58
- const params = new URLSearchParams ( { speak : speaker , text : text } ) ;
71
+ const params = new URLSearchParams ( {
72
+ speak : speaker ,
73
+ text : text
74
+ } ) ;
75
+
76
+ if ( apiName === 'leftsite' ) {
77
+ const rate = $ ( '#rate' ) . val ( ) ;
78
+ const pitch = $ ( '#pitch' ) . val ( ) ;
79
+ params . append ( 'r' , rate ) ;
80
+ params . append ( 'p' , pitch ) ;
81
+ params . append ( 'o' , 'audio-24khz-48kbitrate-mono-mp3' ) ;
82
+ }
59
83
60
84
$ ( '#loading' ) . show ( ) ;
61
85
$ ( '#result' ) . hide ( ) ;
@@ -64,15 +88,11 @@ $(document).ready(function () {
64
88
url : `${ apiUrl } ?${ params . toString ( ) } ` ,
65
89
method : 'GET' ,
66
90
success : function ( data ) {
67
- if ( data . code === 200 ) {
68
- const voiceUrl = apiName === 'aivoice' ? data . voice : data . voiceurl ;
69
- $ ( '#audio' ) . attr ( 'src' , voiceUrl ) ;
70
- $ ( '#download' ) . attr ( 'href' , voiceUrl ) ;
71
- $ ( '#result' ) . show ( ) ;
72
- } else {
73
- alert ( '生成失败,请重试' ) ;
74
- }
75
-
91
+ const voiceUrl = apiName === 'aivoicenet' ? data . voiceurl : `${ apiUrl } ?${ params . toString ( ) } ` ;
92
+ $ ( '#audio' ) . attr ( 'src' , voiceUrl ) ;
93
+ $ ( '#download' ) . attr ( 'href' , voiceUrl ) ;
94
+ $ ( '#result' ) . show ( ) ;
95
+ addHistoryItem ( text , voiceUrl ) ; // 添加到历史记录
76
96
$ ( '#loading' ) . hide ( ) ;
77
97
} ,
78
98
error : function ( ) {
@@ -82,3 +102,37 @@ $(document).ready(function () {
82
102
} ) ;
83
103
} ) ;
84
104
} ) ;
105
+
106
+ function addHistoryItem ( text , audioURL ) {
107
+ const historyItems = $ ( '#historyItems' ) ;
108
+ const historyItem = $ ( `
109
+ <div class="history-item">
110
+ <span>${ text } </span>
111
+ <div>
112
+ <button class="btn btn-secondary" onclick="playAudio('${ audioURL } ')">播放</button>
113
+ <button class="btn btn-info" onclick="downloadAudio('${ audioURL } ')">下载</button>
114
+ </div>
115
+ </div>
116
+ ` ) ;
117
+ historyItems . append ( historyItem ) ;
118
+ }
119
+
120
+ function playAudio ( audioURL ) {
121
+ const audioSource = $ ( '#audioSource' ) ;
122
+ audioSource . attr ( 'src' , audioURL ) ;
123
+
124
+ const audioElement = $ ( '#audioPlayer audio' ) [ 0 ] ;
125
+ audioElement . load ( ) ;
126
+ audioElement . play ( ) ;
127
+ }
128
+
129
+ function downloadAudio ( audioURL ) {
130
+ const link = document . createElement ( 'a' ) ;
131
+ link . href = audioURL ;
132
+ link . download = 'audio.mp3' ;
133
+ link . click ( ) ;
134
+ }
135
+
136
+ function clearHistory ( ) {
137
+ $ ( '#historyItems' ) . empty ( ) ;
138
+ }
0 commit comments