Commit 4296dab5 authored by david's avatar david

Merge branch 'feature/play_audio' into 'master'

Feature/play audio

See merge request !1
parents f848e374 f9984207
......@@ -54,7 +54,7 @@ function execCmd(cmd, params, path) {
let creatorBasePath = 'CocosCreator';
if (process.platform !== 'win32') {
creatorBasePath = "/Applications/CocosCreator/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) {
return new Promise((resolve, reject) => {
......
This diff is collapsed.
......@@ -32,7 +32,9 @@
"node-sass": "4.0.0",
"spark-md5": "^3.0.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": {
"@angular-devkit/build-angular": "~0.900.3",
......
......@@ -142,14 +142,8 @@
<div style="display: flex; align-items: center; justify-content: space-between;">
<div style="display: flex; align-items: center;">
<h4>设置选项-{{j+1}}:</h4>
<!-- <div align="center" style="display: flex; align-items: center; justify-content: center;margin-top: -7px;">
<nz-radio-group [ngModel]="option.answer" (ngModelChange)="radioChange($event, option, 'answer')">
<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> -->
<label style="margin-left: 8px;" nz-checkbox [ngModel]="option.audioAutoPlay !== false" *ngIf="ques.optionTypeAudio"
(ngModelChange)="option.audioAutoPlay = $event; save()">开启播放音频</label>
</div>
<button style="float:right" nz-button nzType="danger" (click)="deleteOptionBtnClick(ques, j)">
x
......@@ -161,7 +155,14 @@
<div style="margin-top: 5px; display: flex; align-items: center; ">
<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 style="margin-top: 5px; display: flex; align-items: center; ">
<span style="">翻译:</span>
......@@ -181,7 +182,7 @@
</button>
</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>
<app-audio-recorder [audioUrl]="option.audio_url"
(audioUploaded)="onItemAudioUploadSuccess($event, option, 'audio_url')">
......
......@@ -3,6 +3,10 @@ import { JsonPipe } from '@angular/common';
import { NzMessageService } from 'ng-zorro-antd/message';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
declare function commonPostMessageWithCallback(
params: any,
callback: (res: any) => void
): void;
@Component({
selector: 'app-form',
......@@ -54,10 +58,50 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
selectedWord: any;
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() {
......@@ -165,7 +209,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
} else if (ques.optionArr.length < ques.optionCount) {
for (let i = ques.optionArr.length; i < ques.optionCount; i++) {
ques.optionArr.push({
audioAutoPlay: true
});
}
}
......@@ -346,7 +390,9 @@ getUnusedWord(ques: any): any {
addOnePageBtnClick() {
const ques = {
optionArr:[{}],
optionArr:[{
audioAutoPlay: true
}],
quesTypeText: true,
quesTypeAudio: true,
quesTypePic: true,
......@@ -368,6 +414,7 @@ getUnusedWord(ques: any): any {
addOneOption(ques) {
ques.optionArr.push({
audioAutoPlay: true
// answer: 'isWrong'
});
this.save();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment