Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
JJ_Game_Card
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
JJ_Game_Card
Commits
dc9113fb
Commit
dc9113fb
authored
Apr 21, 2026
by
JinWei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 生成音频
parent
f848e374
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
257 additions
and
186 deletions
+257
-186
buildCocos.js
bin/buildCocos.js
+1
-1
package-lock.json
form/package-lock.json
+192
-171
package.json
form/package.json
+3
-1
form.component.html
form/src/app/form/form.component.html
+11
-10
form.component.ts
form/src/app/form/form.component.ts
+50
-3
No files found.
bin/buildCocos.js
View file @
dc9113fb
...
@@ -54,7 +54,7 @@ function execCmd(cmd, params, path) {
...
@@ -54,7 +54,7 @@ function execCmd(cmd, params, path) {
let
creatorBasePath
=
'
CocosCreator
'
;
let
creatorBasePath
=
'
CocosCreator
'
;
if
(
process
.
platform
!==
'
win32
'
)
{
if
(
process
.
platform
!==
'
win32
'
)
{
creatorBasePath
=
"
/Applications/Cocos
Creator
/Creator/2.4.5/CocosCreator.app/Contents/MacOS/CocosCreator
"
;
creatorBasePath
=
"
/Applications/Cocos/Creator/2.4.5/CocosCreator.app/Contents/MacOS/CocosCreator
"
;
}
}
const
buildCocos
=
function
(
args
)
{
const
buildCocos
=
function
(
args
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
form/package-lock.json
View file @
dc9113fb
This diff is collapsed.
Click to expand it.
form/package.json
View file @
dc9113fb
...
@@ -32,7 +32,9 @@
...
@@ -32,7 +32,9 @@
"node-sass"
:
"4.0.0"
,
"node-sass"
:
"4.0.0"
,
"spark-md5"
:
"^3.0.0"
,
"spark-md5"
:
"^3.0.0"
,
"tslib"
:
"^1.10.0"
,
"tslib"
:
"^1.10.0"
,
"zone.js"
:
"~0.10.2"
"zone.js"
:
"~0.10.2"
,
"querystring"
:
"^0.2.0"
,
"crypto-js"
:
"^4.1.1"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"@angular-devkit/build-angular"
:
"~0.900.3"
,
"@angular-devkit/build-angular"
:
"~0.900.3"
,
...
...
form/src/app/form/form.component.html
View file @
dc9113fb
...
@@ -142,14 +142,8 @@
...
@@ -142,14 +142,8 @@
<div
style=
"display: flex; align-items: center; justify-content: space-between;"
>
<div
style=
"display: flex; align-items: center; justify-content: space-between;"
>
<div
style=
"display: flex; align-items: center;"
>
<div
style=
"display: flex; align-items: center;"
>
<h4>
设置选项-{{j+1}}:
</h4>
<h4>
设置选项-{{j+1}}:
</h4>
<!-- <div align="center" style="display: flex; align-items: center; justify-content: center;margin-top: -7px;">
<label
style=
"margin-left: 8px;"
nz-checkbox
[(
ngModel
)]="
option
.
audioAutoPlay
"
*
ngIf=
"ques.optionTypeAudio"
<nz-radio-group [ngModel]="option.answer" (ngModelChange)="radioChange($event, option, 'answer')">
(
ngModelChange
)="
save
()"
>
开启播放音频
</label>
<div style="display: flex; flex-wrap: wrap; width: 100%;">
<label style="margin-left: 5px;" nz-radio [nzValue]="'isRight'">{{'正确'}}</label>
<label style="margin-left: 5px;" nz-radio [nzValue]="'isWrong'">{{'错误'}}</label>
</div>
</nz-radio-group>
</div> -->
</div>
</div>
<button
style=
"float:right"
nz-button
nzType=
"danger"
(
click
)="
deleteOptionBtnClick
(
ques
,
j
)"
>
<button
style=
"float:right"
nz-button
nzType=
"danger"
(
click
)="
deleteOptionBtnClick
(
ques
,
j
)"
>
x
x
...
@@ -161,7 +155,14 @@
...
@@ -161,7 +155,14 @@
<div
style=
"margin-top: 5px; display: flex; align-items: center; "
>
<div
style=
"margin-top: 5px; display: flex; align-items: center; "
>
<span
style=
""
>
文本:
</span>
<span
style=
""
>
文本:
</span>
<input
type=
"text"
nz-input
[(
ngModel
)]="
option
.
text
"
(
blur
)="
save
()"
style=
" width: 300px;"
>
<input
type=
"text"
nz-input
[(
ngModel
)]="
option
.
text
"
(
blur
)="
save
()"
style=
" width: 300px; margin-right: 8px;"
>
<app-audio-recorder
[
audioUrl
]="
option
.
audio_url
"
(
audioUploaded
)="
onItemAudioUploadSuccess
($
event
,
option
,
'
audio_url
')"
>
</app-audio-recorder>
<button
nz-button
nzType=
"primary"
(
click
)="
generateTTSHandle
(
option
,
option
.
text
,
'
audio_url
')"
style=
"width: 120px; height: 32px; margin-left: 8px;"
>
<i
nz-icon
nzType=
"plus-circle"
nzTheme=
"outline"
></i>
生成音频
</button>
</div>
</div>
<!-- <div style="margin-top: 5px; display: flex; align-items: center; ">
<!-- <div style="margin-top: 5px; display: flex; align-items: center; ">
<span style="">翻译:</span>
<span style="">翻译:</span>
...
@@ -181,7 +182,7 @@
...
@@ -181,7 +182,7 @@
</button>
</button>
</div>
</div>
<div
*
ngIf=
"ques.optionTypeAudio"
style=
"margin-top: 10px; display: flex; align-items: center;"
>
<div
*
ngIf=
"ques.optionTypeAudio
&& !ques.optionTypeText
"
style=
"margin-top: 10px; display: flex; align-items: center;"
>
<span
style=
""
>
音频:
</span>
<span
style=
""
>
音频:
</span>
<app-audio-recorder
[
audioUrl
]="
option
.
audio_url
"
<app-audio-recorder
[
audioUrl
]="
option
.
audio_url
"
(
audioUploaded
)="
onItemAudioUploadSuccess
($
event
,
option
,
'
audio_url
')"
>
(
audioUploaded
)="
onItemAudioUploadSuccess
($
event
,
option
,
'
audio_url
')"
>
...
...
form/src/app/form/form.component.ts
View file @
dc9113fb
...
@@ -3,6 +3,10 @@ import { JsonPipe } from '@angular/common';
...
@@ -3,6 +3,10 @@ import { JsonPipe } from '@angular/common';
import
{
NzMessageService
}
from
'
ng-zorro-antd/message
'
;
import
{
NzMessageService
}
from
'
ng-zorro-antd/message
'
;
import
{
HttpClient
,
HttpHeaders
,
HttpParams
}
from
'
@angular/common/http
'
;
import
{
HttpClient
,
HttpHeaders
,
HttpParams
}
from
'
@angular/common/http
'
;
declare
function
commonPostMessageWithCallback
(
params
:
any
,
callback
:
(
res
:
any
)
=>
void
):
void
;
@
Component
({
@
Component
({
selector
:
'
app-form
'
,
selector
:
'
app-form
'
,
...
@@ -54,10 +58,50 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
...
@@ -54,10 +58,50 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
selectedWord
:
any
;
selectedWord
:
any
;
constructor
(
private
appRef
:
ApplicationRef
,
private
changeDetectorRef
:
ChangeDetectorRef
,
constructor
(
private
appRef
:
ApplicationRef
,
private
changeDetectorRef
:
ChangeDetectorRef
,
private
message
:
NzMessageService
,
private
http
:
HttpClient
)
{
private
message
:
NzMessageService
,
private
http
:
HttpClient
,
private
nzMessageService
:
NzMessageService
)
{
}
}
async
generateTTSHandle
(
obj
,
text
,
key
=
'
audio
'
)
{
if
(
!
text
)
{
this
.
nzMessageService
.
error
(
'
文本不能为空
'
);
return
;
}
this
.
nzMessageService
.
loading
(
'
生成音频中...
'
);
const
audioUrl
=
await
this
.
generateTTS
(
text
).
catch
((
e
)
=>
{
this
.
nzMessageService
.
error
(
'
生成音频失败
'
);
}).
finally
(()
=>
{
this
.
nzMessageService
.
remove
();
});
if
(
!
audioUrl
)
{
this
.
nzMessageService
.
error
(
'
生成音频失败,请稍后再试。
'
);
return
;
}
obj
[
key
]
=
audioUrl
;
this
.
save
();
}
async
generateTTS
(
sentence
:
string
):
Promise
<
string
>
{
if
(
typeof
commonPostMessageWithCallback
!==
'
function
'
)
{
throw
new
Error
(
'
通信方法不可用
'
);
}
return
new
Promise
<
string
>
((
resolve
,
reject
)
=>
{
commonPostMessageWithCallback
(
{
action
:
'
generateTTS
'
,
data
:
sentence
},
(
res
:
string
|
object
)
=>
{
const
resData
=
typeof
res
===
'
string
'
?
JSON
.
parse
(
res
)
:
res
;
if
(
resData
.
msg
==
'
success
'
&&
resData
.
data
)
{
resolve
(
resData
.
data
as
unknown
as
string
);
}
else
{
reject
(
'
音频生成失败
'
);
}
}
);
}).
catch
(()
=>
{
throw
new
Error
(
'
音频生成失败
'
);
});
}
ngOnInit
()
{
ngOnInit
()
{
...
@@ -165,7 +209,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
...
@@ -165,7 +209,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
}
else
if
(
ques
.
optionArr
.
length
<
ques
.
optionCount
)
{
}
else
if
(
ques
.
optionArr
.
length
<
ques
.
optionCount
)
{
for
(
let
i
=
ques
.
optionArr
.
length
;
i
<
ques
.
optionCount
;
i
++
)
{
for
(
let
i
=
ques
.
optionArr
.
length
;
i
<
ques
.
optionCount
;
i
++
)
{
ques
.
optionArr
.
push
({
ques
.
optionArr
.
push
({
audioAutoPlay
:
true
});
});
}
}
}
}
...
@@ -346,7 +390,9 @@ getUnusedWord(ques: any): any {
...
@@ -346,7 +390,9 @@ getUnusedWord(ques: any): any {
addOnePageBtnClick
()
{
addOnePageBtnClick
()
{
const
ques
=
{
const
ques
=
{
optionArr
:[{}],
optionArr
:[{
audioAutoPlay
:
true
}],
quesTypeText
:
true
,
quesTypeText
:
true
,
quesTypeAudio
:
true
,
quesTypeAudio
:
true
,
quesTypePic
:
true
,
quesTypePic
:
true
,
...
@@ -368,6 +414,7 @@ getUnusedWord(ques: any): any {
...
@@ -368,6 +414,7 @@ getUnusedWord(ques: any): any {
addOneOption
(
ques
)
{
addOneOption
(
ques
)
{
ques
.
optionArr
.
push
({
ques
.
optionArr
.
push
({
audioAutoPlay
:
true
// answer: 'isWrong'
// answer: 'isWrong'
});
});
this
.
save
();
this
.
save
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment