fmode-ng 0.0.66 → 0.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2022/lib/aigc/avatar/comp-avatar-talk/comp-avatar-talk.component.mjs +1 -1
- package/esm2022/lib/aigc/service-fmai/service-chat/chat-class.mjs +1 -1
- package/esm2022/lib/aigc/voice/fmode-voice.service.mjs +1 -1
- package/esm2022/lib/aigc/voice/stream.player.mjs +1 -1
- package/esm2022/lib/aigc/voice/tts/fmode-tts-class.mjs +1 -1
- package/esm2022/lib/storage/service-upload/nova-upload.service.mjs +1 -1
- package/esm2022/lib/storage/storage.module.mjs +1 -1
- package/fesm2022/fmode-ng.mjs +1 -1
- package/fesm2022/fmode-ng.mjs.map +1 -1
- package/lib/aigc/voice/fmode-voice.service.d.ts +2 -2
- package/lib/aigc/voice/stream.player.d.ts +1 -1
- package/lib/storage/service-upload/nova-upload.service.d.ts +2 -2
- package/package.json +1 -1
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* 保留所有权利 All Rights Reserved.
|
|
6
6
|
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/aigc/avatar/comp-avatar-talk/comp-avatar-talk.component.mjs
|
|
7
7
|
*/
|
|
8
|
-
import{Component,ElementRef,ViewChild}from"@angular/core";import{FmodeVoiceService}from"../../voice";import{ChatService}from"../../service-fmai/service-chat";import{IonicModule,NavController,Platform,ModalController}from"@ionic/angular";import{CommonModule}from"@angular/common";import{CompAvatarParticleComponent}from"../comp-avatar-particle/comp-avatar-particle.component";import{CompAvatarRoleImageComponent}from"../comp-avatar-role-image/comp-avatar-role-image.component";import{FormsModule}from"@angular/forms";import{ActivatedRoute,Router,RouterModule}from"@angular/router";import*as Parse from"parse";import{NovaCloudService}from"../../../nova-cloud/nova-cloud.service";import{HidexmlPipe}from"../../service-fmai/service-chat";import{ModalChatVoiceInputComponent}from"../modal-chat-voice-input/modal-chat-voice-input.component";import{Diagnostic}from"@awesome-cordova-plugins/diagnostic/ngx";import*as i0 from"@angular/core";import*as i1 from"../../voice";import*as i2 from"@ionic/angular";import*as i3 from"@angular/router";import*as i4 from"../../service-fmai/service-chat";import*as i5 from"../../../nova-cloud/nova-cloud.service";import*as i6 from"@angular/common";export class CompAvatarTalkComponent{constructor(o,e,n,t,i,a,r){this.voiceServ=o,this.platform=e,this.router=n,this.navCtrl=t,this.route=i,this.chatServ=a,this.ncloud=r,this.route.paramMap.subscribe((o=>{this.roleId=o.get("roleId"),this.loadAvatarRole(this.roleId)})),document.body.classList.add("dark")}ngOnInit(){}ngOnDestroy(){document.body.classList.remove("dark"),this.voiceServ.resultText=null,this.fmodeChat&&(this.fmodeChat.latestAIResponse=null)}goBack(){document.body.classList.remove("dark");let o=this.avatarRole?.get("backUrl");try{if(o)return void this.navCtrl.navigateRoot(o);this.navCtrl.navigateRoot("/chat/pro/role/"+this.roleId)}catch(o){this.navCtrl.navigateRoot("/chat/pro/role/"+this.roleId)}}async loadAvatarRole(o){let e=new Parse.Query("AvatarRole");this.avatarRole=await e.get(o);let n=await this.chatServ.createNewRoleChat(this.roleId);n.isTalkMode=!0,this.fmodeChat=n,this.fmodeChat.showAvatar()}ngAfterViewInit(){this.listenDivChange()}listenDivChange(){new MutationObserver((()=>{this.scrollToBottom(this.aiRespComp)})).observe(this.aiRespComp.nativeElement,{childList:!0,subtree:!0,attributes:!0})}scrollToBottom(o){o?.nativeElement?.scrollHeight&&(o.nativeElement.scrollTop=o.nativeElement.scrollHeight)}static{this.ɵfac=i0.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:CompAvatarTalkComponent,deps:[{token:i1.FmodeVoiceService},{token:i2.Platform},{token:i3.Router},{token:i2.NavController},{token:i3.ActivatedRoute},{token:i4.ChatService},{token:i5.NovaCloudService}],target:i0.ɵɵFactoryTarget.Component})}static{this.ɵcmp=i0.ɵɵngDeclareComponent({minVersion:"14.0.0",version:"17.3.12",type:CompAvatarTalkComponent,isStandalone:!0,selector:"app-comp-avatar-talk",providers:[FmodeVoiceService,NovaCloudService,ChatService,Diagnostic,ModalController],viewQueries:[{propertyName:"avatarComp",first:!0,predicate:["avatar"],descendants:!0},{propertyName:"aiRespComp",first:!0,predicate:["aiRespComp"],descendants:!0}],ngImport:i0,template:'<ion-menu #menu contentId="main-content" side="end">\n <ion-header>\n <ion-toolbar>\n <ion-title>资料</ion-title>\n </ion-toolbar>\n </ion-header>\n <ion-content class="ion-padding">\n\n <ion-card style="margin: 0px;">\n <img [src]="avatarRole?.get(\'thumb\')" alt="">\n <ion-card-header>\n <ion-card-subtitle>{{avatarRole?.get(\'tags\')}}</ion-card-subtitle>\n <ion-card-title>{{avatarRole?.get("name")}}</ion-card-title>\n </ion-card-header>\n \n <ion-card-content>\n {{avatarRole?.get("desc")}}\n\n <ion-list [inset]="true" style="margin:0px;">\n \x3c!-- <ion-item>\n <ion-avatar *ngIf="avatarRole?.get(\'thumb\')" aria-hidden="true" slot="start">\n <img [src]="avatarRole?.get(\'thumb\')" />\n </ion-avatar>\n <ion-label>{{avatarRole?.get("name")}}</ion-label>\n </ion-item> --\x3e\n <ion-item lines="none" *ngIf="avatarRole?.get(\'age\')">\n <ion-note slot="start">年龄</ion-note>\n <ion-label>{{avatarRole?.get("age")}}</ion-label>\n </ion-item>\n <ion-item lines="none" *ngIf="avatarRole?.get(\'gender\')">\n <ion-note slot="start">性别</ion-note>\n <ion-label>{{avatarRole?.get("gender")}}</ion-label>\n </ion-item>\n <ion-item lines="none">\n <ion-note slot="start">称号</ion-note>\n <ion-label>{{avatarRole?.get("title")}}</ion-label>\n </ion-item>\n \n <ion-item lines="none">\n <ion-note slot="start">擅长</ion-note>\n <ion-label>{{avatarRole?.get("tags")?.join(\',\')}}</ion-label>\n </ion-item>\n\n </ion-list>\n </ion-card-content>\n </ion-card>\n \n \n \n </ion-content>\n</ion-menu>\n\n<div class="ion-page" id="main-content">\n <ion-header class="ion-no-border">\n <ion-toolbar>\n <ion-buttons slot="start">\n <ion-button (click)="goBack()"> <ion-icon name="chevron-back-outline"></ion-icon> </ion-button>\n </ion-buttons>\n <ion-title>\n <ion-chip *ngIf="avatarRole?.get(\'title\')">{{avatarRole?.get("title")}}</ion-chip>\n </ion-title>\n <ion-buttons slot="end">\n \x3c!-- <ion-button (click)="playTTSTeting()">TTS测试</ion-button> --\x3e\n {{avatarRole?.get("name")}}\n <ion-button (click)="menu.toggle()"> <ion-icon name="ellipsis-horizontal-outline"></ion-icon> </ion-button>\n </ion-buttons>\n </ion-toolbar>\n </ion-header>\n\n \x3c!-- <ion-segment value="voice">\n <ion-segment-button (click)="chatServ.createChatPanel(avatarRole)" value="chat">\n <ion-label>聊天</ion-label>\n </ion-segment-button>\n <ion-segment-button routerLink="{{\'/avatar/role/\'+avatarRole?.id}}" value="voice">\n <ion-label>语音</ion-label>\n </ion-segment-button>\n </ion-segment> --\x3e\n\n \x3c!-- 数字形象:动画效果 --\x3e\n <fm-avatar-role-image *ngIf="avatarRole&&fmodeChat" [fmodeChat]="fmodeChat" [role]="avatarRole" #avatar class="avatar"></fm-avatar-role-image>\n \x3c!-- <fm-avatar-role-particle #avatar class="avatar"></fm-avatar-role-particle> --\x3e\n\n \x3c!-- AI回复的最新消息 --\x3e\n <div class="ai-resp-input" #aiRespComp>{{fmodeChat?.latestAIResponse | hidexml}}</div>\n\n <fm-modal-chat-voice-input *ngIf="fmodeChat" [fmodeChat]="fmodeChat"></fm-modal-chat-voice-input>\n\n</div>\n\n',styles:["ion-menu ion-note{color:#ccc;font-weight:700}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.avatar{display:block;width:100%;height:100%}.ai-resp-input{font-size:1rem;color:#fff;position:fixed;top:60px;max-height:15vh;overflow-y:scroll;padding:0 10px}.user-asr-input{font-size:1rem;color:#fff;position:fixed;bottom:6vh;padding:0 10px}.test-button-group{color:#00f;position:fixed;bottom:20vh}.test-button-group button{padding:10px;margin:10px}\n"],dependencies:[{kind:"ngmodule",type:CommonModule},{kind:"directive",type:i6.NgIf,selector:"[ngIf]",inputs:["ngIf","ngIfThen","ngIfElse"]},{kind:"ngmodule",type:RouterModule},{kind:"ngmodule",type:FormsModule},{kind:"ngmodule",type:IonicModule},{kind:"component",type:i2.IonButton,selector:"ion-button",inputs:["buttonType","color","disabled","download","expand","fill","form","href","mode","rel","routerAnimation","routerDirection","shape","size","strong","target","type"]},{kind:"component",type:i2.IonButtons,selector:"ion-buttons",inputs:["collapse"]},{kind:"component",type:i2.IonCard,selector:"ion-card",inputs:["button","color","disabled","download","href","mode","rel","routerAnimation","routerDirection","target","type"]},{kind:"component",type:i2.IonCardContent,selector:"ion-card-content",inputs:["mode"]},{kind:"component",type:i2.IonCardHeader,selector:"ion-card-header",inputs:["color","mode","translucent"]},{kind:"component",type:i2.IonCardSubtitle,selector:"ion-card-subtitle",inputs:["color","mode"]},{kind:"component",type:i2.IonCardTitle,selector:"ion-card-title",inputs:["color","mode"]},{kind:"component",type:i2.IonChip,selector:"ion-chip",inputs:["color","disabled","mode","outline"]},{kind:"component",type:i2.IonContent,selector:"ion-content",inputs:["color","fixedSlotPlacement","forceOverscroll","fullscreen","scrollEvents","scrollX","scrollY"]},{kind:"component",type:i2.IonHeader,selector:"ion-header",inputs:["collapse","mode","translucent"]},{kind:"component",type:i2.IonIcon,selector:"ion-icon",inputs:["color","flipRtl","icon","ios","lazy","md","mode","name","sanitize","size","src"]},{kind:"component",type:i2.IonItem,selector:"ion-item",inputs:["button","color","detail","detailIcon","disabled","download","href","lines","mode","rel","routerAnimation","routerDirection","target","type"]},{kind:"component",type:i2.IonLabel,selector:"ion-label",inputs:["color","mode","position"]},{kind:"component",type:i2.IonList,selector:"ion-list",inputs:["inset","lines","mode"]},{kind:"component",type:i2.IonMenu,selector:"ion-menu",inputs:["contentId","disabled","maxEdgeStart","menuId","side","swipeGesture","type"]},{kind:"component",type:i2.IonNote,selector:"ion-note",inputs:["color","mode"]},{kind:"component",type:i2.IonTitle,selector:"ion-title",inputs:["color","size"]},{kind:"component",type:i2.IonToolbar,selector:"ion-toolbar",inputs:["color","mode"]},{kind:"component",type:CompAvatarRoleImageComponent,selector:"fm-avatar-role-image",inputs:["fmodeChat","role"]},{kind:"component",type:ModalChatVoiceInputComponent,selector:"fm-modal-chat-voice-input",inputs:["fmodeChat","talkMode"]},{kind:"pipe",type:HidexmlPipe,name:"hidexml"}]})}}i0.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:CompAvatarTalkComponent,decorators:[{type:Component,args:[{selector:"app-comp-avatar-talk",standalone:!0,imports:[CommonModule,RouterModule,FormsModule,IonicModule,CompAvatarParticleComponent,CompAvatarRoleImageComponent,ModalChatVoiceInputComponent,HidexmlPipe],providers:[FmodeVoiceService,NovaCloudService,ChatService,Diagnostic,ModalController],template:'<ion-menu #menu contentId="main-content" side="end">\n <ion-header>\n <ion-toolbar>\n <ion-title>资料</ion-title>\n </ion-toolbar>\n </ion-header>\n <ion-content class="ion-padding">\n\n <ion-card style="margin: 0px;">\n <img [src]="avatarRole?.get(\'thumb\')" alt="">\n <ion-card-header>\n <ion-card-subtitle>{{avatarRole?.get(\'tags\')}}</ion-card-subtitle>\n <ion-card-title>{{avatarRole?.get("name")}}</ion-card-title>\n </ion-card-header>\n \n <ion-card-content>\n {{avatarRole?.get("desc")}}\n\n <ion-list [inset]="true" style="margin:0px;">\n \x3c!-- <ion-item>\n <ion-avatar *ngIf="avatarRole?.get(\'thumb\')" aria-hidden="true" slot="start">\n <img [src]="avatarRole?.get(\'thumb\')" />\n </ion-avatar>\n <ion-label>{{avatarRole?.get("name")}}</ion-label>\n </ion-item> --\x3e\n <ion-item lines="none" *ngIf="avatarRole?.get(\'age\')">\n <ion-note slot="start">年龄</ion-note>\n <ion-label>{{avatarRole?.get("age")}}</ion-label>\n </ion-item>\n <ion-item lines="none" *ngIf="avatarRole?.get(\'gender\')">\n <ion-note slot="start">性别</ion-note>\n <ion-label>{{avatarRole?.get("gender")}}</ion-label>\n </ion-item>\n <ion-item lines="none">\n <ion-note slot="start">称号</ion-note>\n <ion-label>{{avatarRole?.get("title")}}</ion-label>\n </ion-item>\n \n <ion-item lines="none">\n <ion-note slot="start">擅长</ion-note>\n <ion-label>{{avatarRole?.get("tags")?.join(\',\')}}</ion-label>\n </ion-item>\n\n </ion-list>\n </ion-card-content>\n </ion-card>\n \n \n \n </ion-content>\n</ion-menu>\n\n<div class="ion-page" id="main-content">\n <ion-header class="ion-no-border">\n <ion-toolbar>\n <ion-buttons slot="start">\n <ion-button (click)="goBack()"> <ion-icon name="chevron-back-outline"></ion-icon> </ion-button>\n </ion-buttons>\n <ion-title>\n <ion-chip *ngIf="avatarRole?.get(\'title\')">{{avatarRole?.get("title")}}</ion-chip>\n </ion-title>\n <ion-buttons slot="end">\n \x3c!-- <ion-button (click)="playTTSTeting()">TTS测试</ion-button> --\x3e\n {{avatarRole?.get("name")}}\n <ion-button (click)="menu.toggle()"> <ion-icon name="ellipsis-horizontal-outline"></ion-icon> </ion-button>\n </ion-buttons>\n </ion-toolbar>\n </ion-header>\n\n \x3c!-- <ion-segment value="voice">\n <ion-segment-button (click)="chatServ.createChatPanel(avatarRole)" value="chat">\n <ion-label>聊天</ion-label>\n </ion-segment-button>\n <ion-segment-button routerLink="{{\'/avatar/role/\'+avatarRole?.id}}" value="voice">\n <ion-label>语音</ion-label>\n </ion-segment-button>\n </ion-segment> --\x3e\n\n \x3c!-- 数字形象:动画效果 --\x3e\n <fm-avatar-role-image *ngIf="avatarRole&&fmodeChat" [fmodeChat]="fmodeChat" [role]="avatarRole" #avatar class="avatar"></fm-avatar-role-image>\n \x3c!-- <fm-avatar-role-particle #avatar class="avatar"></fm-avatar-role-particle> --\x3e\n\n \x3c!-- AI回复的最新消息 --\x3e\n <div class="ai-resp-input" #aiRespComp>{{fmodeChat?.latestAIResponse | hidexml}}</div>\n\n <fm-modal-chat-voice-input *ngIf="fmodeChat" [fmodeChat]="fmodeChat"></fm-modal-chat-voice-input>\n\n</div>\n\n',styles:["ion-menu ion-note{color:#ccc;font-weight:700}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.avatar{display:block;width:100%;height:100%}.ai-resp-input{font-size:1rem;color:#fff;position:fixed;top:60px;max-height:15vh;overflow-y:scroll;padding:0 10px}.user-asr-input{font-size:1rem;color:#fff;position:fixed;bottom:6vh;padding:0 10px}.test-button-group{color:#00f;position:fixed;bottom:20vh}.test-button-group button{padding:10px;margin:10px}\n"]}]}],ctorParameters:()=>[{type:i1.FmodeVoiceService},{type:i2.Platform},{type:i3.Router},{type:i2.NavController},{type:i3.ActivatedRoute},{type:i4.ChatService},{type:i5.NovaCloudService}],propDecorators:{avatarComp:[{type:ViewChild,args:["avatar"]}],aiRespComp:[{type:ViewChild,args:["aiRespComp"]}]}});
|
|
8
|
+
import{Component,ElementRef,ViewChild}from"@angular/core";import{FmodeVoiceService}from"../../voice";import{ChatService}from"../../service-fmai/service-chat";import{IonicModule,NavController,Platform,ModalController}from"@ionic/angular";import{CommonModule}from"@angular/common";import{CompAvatarParticleComponent}from"../comp-avatar-particle/comp-avatar-particle.component";import{CompAvatarRoleImageComponent}from"../comp-avatar-role-image/comp-avatar-role-image.component";import{FormsModule}from"@angular/forms";import{ActivatedRoute,Router,RouterModule}from"@angular/router";import*as Parse from"parse";import{NovaCloudService}from"../../../nova-cloud/nova-cloud.service";import{HidexmlPipe}from"../../service-fmai/service-chat";import{ModalChatVoiceInputComponent}from"../modal-chat-voice-input/modal-chat-voice-input.component";import{DiagnosticOriginal}from"@awesome-cordova-plugins/diagnostic";import*as i0 from"@angular/core";import*as i1 from"../../voice";import*as i2 from"@ionic/angular";import*as i3 from"@angular/router";import*as i4 from"../../service-fmai/service-chat";import*as i5 from"../../../nova-cloud/nova-cloud.service";import*as i6 from"@angular/common";export class CompAvatarTalkComponent{constructor(o,e,n,t,i,a,r){this.voiceServ=o,this.platform=e,this.router=n,this.navCtrl=t,this.route=i,this.chatServ=a,this.ncloud=r,this.route.paramMap.subscribe((o=>{this.roleId=o.get("roleId"),this.loadAvatarRole(this.roleId)})),document.body.classList.add("dark")}ngOnInit(){}ngOnDestroy(){document.body.classList.remove("dark"),this.voiceServ.resultText=null,this.fmodeChat&&(this.fmodeChat.latestAIResponse=null)}goBack(){document.body.classList.remove("dark");let o=this.avatarRole?.get("backUrl");try{if(o)return void this.navCtrl.navigateRoot(o);this.navCtrl.navigateRoot("/chat/pro/role/"+this.roleId)}catch(o){this.navCtrl.navigateRoot("/chat/pro/role/"+this.roleId)}}async loadAvatarRole(o){let e=new Parse.Query("AvatarRole");this.avatarRole=await e.get(o);let n=await this.chatServ.createNewRoleChat(this.roleId);n.isTalkMode=!0,this.fmodeChat=n,this.fmodeChat.showAvatar()}ngAfterViewInit(){this.listenDivChange()}listenDivChange(){new MutationObserver((()=>{this.scrollToBottom(this.aiRespComp)})).observe(this.aiRespComp.nativeElement,{childList:!0,subtree:!0,attributes:!0})}scrollToBottom(o){o?.nativeElement?.scrollHeight&&(o.nativeElement.scrollTop=o.nativeElement.scrollHeight)}static{this.ɵfac=i0.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:CompAvatarTalkComponent,deps:[{token:i1.FmodeVoiceService},{token:i2.Platform},{token:i3.Router},{token:i2.NavController},{token:i3.ActivatedRoute},{token:i4.ChatService},{token:i5.NovaCloudService}],target:i0.ɵɵFactoryTarget.Component})}static{this.ɵcmp=i0.ɵɵngDeclareComponent({minVersion:"14.0.0",version:"17.3.12",type:CompAvatarTalkComponent,isStandalone:!0,selector:"app-comp-avatar-talk",providers:[FmodeVoiceService,NovaCloudService,ChatService,DiagnosticOriginal,ModalController],viewQueries:[{propertyName:"avatarComp",first:!0,predicate:["avatar"],descendants:!0},{propertyName:"aiRespComp",first:!0,predicate:["aiRespComp"],descendants:!0}],ngImport:i0,template:'<ion-menu #menu contentId="main-content" side="end">\n <ion-header>\n <ion-toolbar>\n <ion-title>资料</ion-title>\n </ion-toolbar>\n </ion-header>\n <ion-content class="ion-padding">\n\n <ion-card style="margin: 0px;">\n <img [src]="avatarRole?.get(\'thumb\')" alt="">\n <ion-card-header>\n <ion-card-subtitle>{{avatarRole?.get(\'tags\')}}</ion-card-subtitle>\n <ion-card-title>{{avatarRole?.get("name")}}</ion-card-title>\n </ion-card-header>\n \n <ion-card-content>\n {{avatarRole?.get("desc")}}\n\n <ion-list [inset]="true" style="margin:0px;">\n \x3c!-- <ion-item>\n <ion-avatar *ngIf="avatarRole?.get(\'thumb\')" aria-hidden="true" slot="start">\n <img [src]="avatarRole?.get(\'thumb\')" />\n </ion-avatar>\n <ion-label>{{avatarRole?.get("name")}}</ion-label>\n </ion-item> --\x3e\n <ion-item lines="none" *ngIf="avatarRole?.get(\'age\')">\n <ion-note slot="start">年龄</ion-note>\n <ion-label>{{avatarRole?.get("age")}}</ion-label>\n </ion-item>\n <ion-item lines="none" *ngIf="avatarRole?.get(\'gender\')">\n <ion-note slot="start">性别</ion-note>\n <ion-label>{{avatarRole?.get("gender")}}</ion-label>\n </ion-item>\n <ion-item lines="none">\n <ion-note slot="start">称号</ion-note>\n <ion-label>{{avatarRole?.get("title")}}</ion-label>\n </ion-item>\n \n <ion-item lines="none">\n <ion-note slot="start">擅长</ion-note>\n <ion-label>{{avatarRole?.get("tags")?.join(\',\')}}</ion-label>\n </ion-item>\n\n </ion-list>\n </ion-card-content>\n </ion-card>\n \n \n \n </ion-content>\n</ion-menu>\n\n<div class="ion-page" id="main-content">\n <ion-header class="ion-no-border">\n <ion-toolbar>\n <ion-buttons slot="start">\n <ion-button (click)="goBack()"> <ion-icon name="chevron-back-outline"></ion-icon> </ion-button>\n </ion-buttons>\n <ion-title>\n <ion-chip *ngIf="avatarRole?.get(\'title\')">{{avatarRole?.get("title")}}</ion-chip>\n </ion-title>\n <ion-buttons slot="end">\n \x3c!-- <ion-button (click)="playTTSTeting()">TTS测试</ion-button> --\x3e\n {{avatarRole?.get("name")}}\n <ion-button (click)="menu.toggle()"> <ion-icon name="ellipsis-horizontal-outline"></ion-icon> </ion-button>\n </ion-buttons>\n </ion-toolbar>\n </ion-header>\n\n \x3c!-- <ion-segment value="voice">\n <ion-segment-button (click)="chatServ.createChatPanel(avatarRole)" value="chat">\n <ion-label>聊天</ion-label>\n </ion-segment-button>\n <ion-segment-button routerLink="{{\'/avatar/role/\'+avatarRole?.id}}" value="voice">\n <ion-label>语音</ion-label>\n </ion-segment-button>\n </ion-segment> --\x3e\n\n \x3c!-- 数字形象:动画效果 --\x3e\n <fm-avatar-role-image *ngIf="avatarRole&&fmodeChat" [fmodeChat]="fmodeChat" [role]="avatarRole" #avatar class="avatar"></fm-avatar-role-image>\n \x3c!-- <fm-avatar-role-particle #avatar class="avatar"></fm-avatar-role-particle> --\x3e\n\n \x3c!-- AI回复的最新消息 --\x3e\n <div class="ai-resp-input" #aiRespComp>{{fmodeChat?.latestAIResponse | hidexml}}</div>\n\n <fm-modal-chat-voice-input *ngIf="fmodeChat" [fmodeChat]="fmodeChat"></fm-modal-chat-voice-input>\n\n</div>\n\n',styles:["ion-menu ion-note{color:#ccc;font-weight:700}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.avatar{display:block;width:100%;height:100%}.ai-resp-input{font-size:1rem;color:#fff;position:fixed;top:60px;max-height:15vh;overflow-y:scroll;padding:0 10px}.user-asr-input{font-size:1rem;color:#fff;position:fixed;bottom:6vh;padding:0 10px}.test-button-group{color:#00f;position:fixed;bottom:20vh}.test-button-group button{padding:10px;margin:10px}\n"],dependencies:[{kind:"ngmodule",type:CommonModule},{kind:"directive",type:i6.NgIf,selector:"[ngIf]",inputs:["ngIf","ngIfThen","ngIfElse"]},{kind:"ngmodule",type:RouterModule},{kind:"ngmodule",type:FormsModule},{kind:"ngmodule",type:IonicModule},{kind:"component",type:i2.IonButton,selector:"ion-button",inputs:["buttonType","color","disabled","download","expand","fill","form","href","mode","rel","routerAnimation","routerDirection","shape","size","strong","target","type"]},{kind:"component",type:i2.IonButtons,selector:"ion-buttons",inputs:["collapse"]},{kind:"component",type:i2.IonCard,selector:"ion-card",inputs:["button","color","disabled","download","href","mode","rel","routerAnimation","routerDirection","target","type"]},{kind:"component",type:i2.IonCardContent,selector:"ion-card-content",inputs:["mode"]},{kind:"component",type:i2.IonCardHeader,selector:"ion-card-header",inputs:["color","mode","translucent"]},{kind:"component",type:i2.IonCardSubtitle,selector:"ion-card-subtitle",inputs:["color","mode"]},{kind:"component",type:i2.IonCardTitle,selector:"ion-card-title",inputs:["color","mode"]},{kind:"component",type:i2.IonChip,selector:"ion-chip",inputs:["color","disabled","mode","outline"]},{kind:"component",type:i2.IonContent,selector:"ion-content",inputs:["color","fixedSlotPlacement","forceOverscroll","fullscreen","scrollEvents","scrollX","scrollY"]},{kind:"component",type:i2.IonHeader,selector:"ion-header",inputs:["collapse","mode","translucent"]},{kind:"component",type:i2.IonIcon,selector:"ion-icon",inputs:["color","flipRtl","icon","ios","lazy","md","mode","name","sanitize","size","src"]},{kind:"component",type:i2.IonItem,selector:"ion-item",inputs:["button","color","detail","detailIcon","disabled","download","href","lines","mode","rel","routerAnimation","routerDirection","target","type"]},{kind:"component",type:i2.IonLabel,selector:"ion-label",inputs:["color","mode","position"]},{kind:"component",type:i2.IonList,selector:"ion-list",inputs:["inset","lines","mode"]},{kind:"component",type:i2.IonMenu,selector:"ion-menu",inputs:["contentId","disabled","maxEdgeStart","menuId","side","swipeGesture","type"]},{kind:"component",type:i2.IonNote,selector:"ion-note",inputs:["color","mode"]},{kind:"component",type:i2.IonTitle,selector:"ion-title",inputs:["color","size"]},{kind:"component",type:i2.IonToolbar,selector:"ion-toolbar",inputs:["color","mode"]},{kind:"component",type:CompAvatarRoleImageComponent,selector:"fm-avatar-role-image",inputs:["fmodeChat","role"]},{kind:"component",type:ModalChatVoiceInputComponent,selector:"fm-modal-chat-voice-input",inputs:["fmodeChat","talkMode"]},{kind:"pipe",type:HidexmlPipe,name:"hidexml"}]})}}i0.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:CompAvatarTalkComponent,decorators:[{type:Component,args:[{selector:"app-comp-avatar-talk",standalone:!0,imports:[CommonModule,RouterModule,FormsModule,IonicModule,CompAvatarParticleComponent,CompAvatarRoleImageComponent,ModalChatVoiceInputComponent,HidexmlPipe],providers:[FmodeVoiceService,NovaCloudService,ChatService,DiagnosticOriginal,ModalController],template:'<ion-menu #menu contentId="main-content" side="end">\n <ion-header>\n <ion-toolbar>\n <ion-title>资料</ion-title>\n </ion-toolbar>\n </ion-header>\n <ion-content class="ion-padding">\n\n <ion-card style="margin: 0px;">\n <img [src]="avatarRole?.get(\'thumb\')" alt="">\n <ion-card-header>\n <ion-card-subtitle>{{avatarRole?.get(\'tags\')}}</ion-card-subtitle>\n <ion-card-title>{{avatarRole?.get("name")}}</ion-card-title>\n </ion-card-header>\n \n <ion-card-content>\n {{avatarRole?.get("desc")}}\n\n <ion-list [inset]="true" style="margin:0px;">\n \x3c!-- <ion-item>\n <ion-avatar *ngIf="avatarRole?.get(\'thumb\')" aria-hidden="true" slot="start">\n <img [src]="avatarRole?.get(\'thumb\')" />\n </ion-avatar>\n <ion-label>{{avatarRole?.get("name")}}</ion-label>\n </ion-item> --\x3e\n <ion-item lines="none" *ngIf="avatarRole?.get(\'age\')">\n <ion-note slot="start">年龄</ion-note>\n <ion-label>{{avatarRole?.get("age")}}</ion-label>\n </ion-item>\n <ion-item lines="none" *ngIf="avatarRole?.get(\'gender\')">\n <ion-note slot="start">性别</ion-note>\n <ion-label>{{avatarRole?.get("gender")}}</ion-label>\n </ion-item>\n <ion-item lines="none">\n <ion-note slot="start">称号</ion-note>\n <ion-label>{{avatarRole?.get("title")}}</ion-label>\n </ion-item>\n \n <ion-item lines="none">\n <ion-note slot="start">擅长</ion-note>\n <ion-label>{{avatarRole?.get("tags")?.join(\',\')}}</ion-label>\n </ion-item>\n\n </ion-list>\n </ion-card-content>\n </ion-card>\n \n \n \n </ion-content>\n</ion-menu>\n\n<div class="ion-page" id="main-content">\n <ion-header class="ion-no-border">\n <ion-toolbar>\n <ion-buttons slot="start">\n <ion-button (click)="goBack()"> <ion-icon name="chevron-back-outline"></ion-icon> </ion-button>\n </ion-buttons>\n <ion-title>\n <ion-chip *ngIf="avatarRole?.get(\'title\')">{{avatarRole?.get("title")}}</ion-chip>\n </ion-title>\n <ion-buttons slot="end">\n \x3c!-- <ion-button (click)="playTTSTeting()">TTS测试</ion-button> --\x3e\n {{avatarRole?.get("name")}}\n <ion-button (click)="menu.toggle()"> <ion-icon name="ellipsis-horizontal-outline"></ion-icon> </ion-button>\n </ion-buttons>\n </ion-toolbar>\n </ion-header>\n\n \x3c!-- <ion-segment value="voice">\n <ion-segment-button (click)="chatServ.createChatPanel(avatarRole)" value="chat">\n <ion-label>聊天</ion-label>\n </ion-segment-button>\n <ion-segment-button routerLink="{{\'/avatar/role/\'+avatarRole?.id}}" value="voice">\n <ion-label>语音</ion-label>\n </ion-segment-button>\n </ion-segment> --\x3e\n\n \x3c!-- 数字形象:动画效果 --\x3e\n <fm-avatar-role-image *ngIf="avatarRole&&fmodeChat" [fmodeChat]="fmodeChat" [role]="avatarRole" #avatar class="avatar"></fm-avatar-role-image>\n \x3c!-- <fm-avatar-role-particle #avatar class="avatar"></fm-avatar-role-particle> --\x3e\n\n \x3c!-- AI回复的最新消息 --\x3e\n <div class="ai-resp-input" #aiRespComp>{{fmodeChat?.latestAIResponse | hidexml}}</div>\n\n <fm-modal-chat-voice-input *ngIf="fmodeChat" [fmodeChat]="fmodeChat"></fm-modal-chat-voice-input>\n\n</div>\n\n',styles:["ion-menu ion-note{color:#ccc;font-weight:700}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.avatar{display:block;width:100%;height:100%}.ai-resp-input{font-size:1rem;color:#fff;position:fixed;top:60px;max-height:15vh;overflow-y:scroll;padding:0 10px}.user-asr-input{font-size:1rem;color:#fff;position:fixed;bottom:6vh;padding:0 10px}.test-button-group{color:#00f;position:fixed;bottom:20vh}.test-button-group button{padding:10px;margin:10px}\n"]}]}],ctorParameters:()=>[{type:i1.FmodeVoiceService},{type:i2.Platform},{type:i3.Router},{type:i2.NavController},{type:i3.ActivatedRoute},{type:i4.ChatService},{type:i5.NovaCloudService}],propDecorators:{avatarComp:[{type:ViewChild,args:["avatar"]}],aiRespComp:[{type:ViewChild,args:["aiRespComp"]}]}});
|
|
9
9
|
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9haWdjL2F2YXRhci9jb21wLWF2YXRhci10YWxrL2NvbXAtYXZhdGFyLXRhbGsuY29tcG9uZW50Lm1qcw==`
|
|
10
10
|
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* 保留所有权利 All Rights Reserved.
|
|
6
6
|
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/aigc/service-fmai/service-chat/chat-class.mjs
|
|
7
7
|
*/
|
|
8
|
-
import{bufferTime,concatMap,Observable,delay,finalize}from"rxjs";import Parse from"parse";import{AgentPrompt}from"../../agent";import{FmodeTTS}from"../../voice/tts";import{PromptTemplate}from"@langchain/core/prompts";const API_BASE="https://server.fmode.cn/api/apig/aigc/gpt",agentPrompt=new AgentPrompt,PromptTplTalkSSMLOutputCode="talk-ssml-output-tpl",PromptTplTalkTextSSMLCode="talk-text-ssml-tpl";export function getMessageContentText(t){let e="";return"string"==typeof t&&(e=t),"object"==typeof t&&(e=t?.find((t=>t?.text))?.text||""),e}export function getMessageImageUrl(t){return"object"==typeof t?t?.find((t=>t?.image_url))?.image_url?.url||"":null}export class FmodeChat{async loadModelList(t){if(this.modelList?.length)return;let e=new Parse.Query("ChatModel");e.notEqualTo("isDeleted",!0),e.equalTo("isEnabled",!0),e.addAscending("index"),this.modelList=await e.find(),this.currentModel=t||this.modelList?.find((t=>"fmode-4.5-128k"==t.get("code")))}showAvatar(){this.avatarConfig=this.role?.get("avatarConfig"),this.avatarConfig&&(this.isAvatarShow=!0,this.avatarConfig?.image&&(this.avatarConfig.image.waiting=this.avatarConfig.image.waiting||this.role?.get("thumb")||this.role?.get("avatar"),this.avatarMode="image"),this.avatarConfig?.video&&(this.avatarConfig.video.waiting=this.avatarConfig.video.waiting,this.avatarMode="video"))}scrollToBottom(t){t=t||this.scrollComp,t?.nativeElement?.scrollHeight&&(t.nativeElement.scrollTop=t.nativeElement.scrollHeight)}constructor(t,e,s,i,o,n,a){this.ChatSession=Parse.Object.extend("ChatSession"),this.messageList=[{role:"system",content:"系统提示:AI仅供参考"}],this.latestAIResponse="",this.userInput="",this.userImage="",this.isDirect=!1,this.mode="page",this.hideShare=!1,this.hideModalSelect=!1,this.hideInputPreview=!1,this.isAvatarShow=!1,this.avatarMode="",this.isPromptModalOpen=!1,this.isPromptMessageAreaShow=!0,this.promptList=[],this.focusUserInput=()=>{},this.leftButtons=[{title:"灵感",icon:"color-wand-outline",onClick:()=>{this.isPromptModalOpen=!0},show:()=>this?.promptList?.length},{title:"角色",icon:"people-outline",onClick:()=>{this.navCtrl?.navigateRoot("/chat/pro/mask")},show:()=>!0},{title:"呼叫",icon:"call-outline",onClick:()=>{this.chatServ?.callRole(this.role)},show:()=>this?.role?.get("voiceConfig")}],this.isVoiceInputMode=!1,this.isTexting=!1,this.isTalkMode=!1,this.SSMLRoleVoice="zh-CN-XiaoxiaoNeural",this.playAnimation=t=>{console.log(t)},this.welcome=async()=>{let t=this.messageList?.filter((t=>"assistant"==t?.role));if(t?.length)return;let e=Parse.User.current(),s=await this.loadSelf("Person","userVerify"),i=await this.loadSelf("Profile","user"),o=e?.get("nickname")||i?.get("name")||e?.get("realname")||e?.get("name"),n=s?.get("name")||s?.get("userVefiry")?.get("realname")||s?.get("userVefiry")?.get("nickname");s?.get("userVerify")?.id==e?.id&&(n="您");let a=this.role.get("voiceConfig")?.welcome?.prompt;if(this.role.get("voiceConfig")?.welcome?.promptList?.length){let t=this.role.get("voiceConfig")?.welcome?.promptList;a=t[Math.floor(Math.random()*t.length)]}if(!a)return;let r=await PromptTemplate.fromTemplate(a,{templateFormat:"mustache"}).format({name:o,userName:o,personName:n,timeOfDay:this.getTimeOfDay()}),l=await this.getVoiceByContentText(r),h={role:"assistant",voice:l,content:r,complete:!0};this.voiceMap[l?.id],this.playChatVoice(this.voiceMap[l?.id]),this.messageList.push(h)},this.self={},this.voiceMap={},this.VoiceTTSMap={},this.chatServ=i,this.role=e,this.sessionId=t,this.navCtrl=o,this.ncloud=n,this.uploadServ=a,s?.id&&(this.chatSession=s,this.messageList=this.chatSession.get("messageList"),this.sessionId=s?.id),this.role?.id&&(this.voiceConfig=this.role?.get("voiceConfig"),this.voiceConfig?.autoTalk&&(this.isTalkMode=!0,this.isDirect=!0))}getTimeOfDay(){const t=(new Date).getHours();return t>=5&&t<12?"早上":t>=12&&t<14?"中午":t>=14&&t<18?"下午":"晚上"}async loadSelf(t,e){if(this.self[t])return this.self[t];let s=Parse.User.current(),i=new Parse.Query(t);return i.include(e),i.equalTo(e,s?.id),this.self[t]=await i.first(),this.self[t]}async loadTalkSystemPrompt(t){if(!this.isTalkMode)return;if(!t)return;"男"==t?.get("gender")?this.SSMLRoleVoice="zh-CN-YunyeNeural":this.SSMLRoleVoice="zh-CN-XiaoxiaoNeural",this.SSMLRoleVoice=t?.get("voiceConfig")?.voice||this.SSMLRoleVoice;let e=await agentPrompt.getFormatTpl("talk-ssml-output-tpl",{SSMLRoleVoice:this.SSMLRoleVoice}),s=t.get("prompt")||"请你扮演飞码AI的人工智能专家。";s+=e;let i={role:"user",content:s,hidden:!0},o=this.messageList?.map((t=>t?.content)).join();if(o.indexOf(s)>-1)return;let n=this.messageList?.findIndex((t=>"system"==t?.role)),a=n+1;this.messageList.splice(a,0,i)}loadRolePrompt(){let t=this.role?.get("prompt"),e={role:"user",content:t,hidden:!0};if(!t)return;let s=this.messageList?.map((t=>t?.content)).join();if(s.indexOf(t)>-1)return;let i=this.messageList?.findIndex((t=>"system"==t?.role)),o=i+1;this.messageList.splice(o,0,e)}async sendMessage(t="FmodeAiTest测试问题",e,s,i,o){if(this.scrollToBottom&&this.scrollToBottom(),this.isPromptMessageAreaShow=!1,this.loadRolePrompt(),e){let s={role:"user",content:[{type:"image_url",image_url:{url:e}},{type:"text",text:t}],complete:!0,createdAt:new Date};o&&(s.voice={id:o?.id}),this.messageList.push({role:"user",content:[{type:"image_url",image_url:{url:e}},{type:"text",text:t}],complete:!0,createdAt:new Date})}else{let e={role:"user",content:t,complete:!0,createdAt:new Date};o&&(e.voice={id:o?.id,duration:o?.duration}),this.messageList.push(e)}let n=new FmodeChatCompletion(this.fixMessageList(this.messageList),{model:this.chatServ?.currentModel?.get("code")||"fmode-4.5-128k"});if(this.onUserSend){if(!await this.onUserSend(this,this.messageList[this.messageList?.length-1]))return}this.userInput="",this.userImage="";let a=this.isDirect||!1;this.isTalkMode&&(a=!0);let r=n.sendCompletion({isDirect:a,onComplete:s||null}).pipe(finalize((async()=>{if(this.isTalkMode){let t=this.messageList[n.indexOfList]?.content,e=await this.getVoiceByContentText(t,i);i?.onSSMLComplete&&i?.onSSMLComplete(e),this.messageList[n.indexOfList].voice=e,this.playChatVoice(this.voiceMap[e?.id])}this.messageList[n.indexOfList].complete=!0}))).subscribe((t=>{this.messageList[n.indexOfList]=t,this.latestAIResponse=this.getContentText(t?.content);let e=this.chatSession?.get("messageList")?.length;this.messageList?.length>e&&this.saveChatSession(),t?.complete&&(this.onMessage&&this.onMessage(this,this.messageList[this.messageList?.length-1]),this.saveChatSession(),r.unsubscribe()),this.scrollToBottom&&this.scrollToBottom()}))}getVoiceByContentText(t,e,s=!1){let i=this.getContentText(t),o=new(Parse.Object.extend("ChatVoice")),n="";return this.SSMLRoleVoice=this.role?.get("voiceConfig")?.voice||this.SSMLRoleVoice,new Promise((async(t,e)=>{let resolveChatVoice=async()=>{o.set("content",i),o.set("ssml",n),o.set("role","assistant");let e=localStorage.getItem("company");e&&o.set("company",{__type:"Pointer",className:"Company",objectId:e}),Parse.User.current()?.id&&o.set("user",Parse.User.current().toPointer()),this.chatSession?.id&&o.set("session",this.chatSession?.toPointer()),o=await o.save(),this.voiceMap[o?.id]=o,t({id:o?.id})};if(0==s&&(n=`<speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" version="1.0" xml:lang="zh-CN"><voice name="${this.SSMLRoleVoice}">${i}</voice></speak>`,resolveChatVoice()),1==s){let t=await agentPrompt.getFormatTpl("talk-text-ssml-tpl",{content:i,SSMLRoleVoice:this.SSMLRoleVoice});new FmodeChatCompletion(this.fixMessageList([{role:"user",content:t}]),{model:this.chatServ?.currentModel?.get("code")||"fmode-4.5-128k"}).sendCompletion({isDirect:!0}).subscribe((async t=>{t?.complete&&(n=this.getContentText(t?.content),resolveChatVoice())}))}}))}getContentText(t){return"string"==typeof t?t:t?.[0]?.text||""}async initTTS(){let t=await this.ncloud.apig("voice/tts/token",{company:localStorage.getItem("company")});if(console.log(t),t?.token){return new FmodeTTS(t,this.uploadServ)}return null}stopPlayingVoice(){Object.values(this.VoiceTTSMap).forEach((t=>{t?.isPlaying&&t?.stop()}))}async playChatVoice(t,e){let s=await this.initTTS();if(s){try{this.playAnimation("talking"),s.speakAsync(t?.get("ssml"),t,{onStart:t=>{e?.onStart&&e?.onStart(t)},onLoaded:t=>{e?.onLoaded&&e?.onLoaded(t)},onStop:()=>{e?.onStop&&e?.onStop(),this.playAnimation("waiting")}})}catch(t){console.error(t)}return this.VoiceTTSMap[t.id]=s,s}return null}async saveChatSession(){if("new"==this.sessionId&&(this.chatSession=new this.ChatSession),this.chatSession.set("title",this.genTitle()),this.chatSession.set("role",this.role?.toPointer()),this.chatSession.set("messageList",this.messageList),this.chatSession.set("user",Parse.User.current()?.toPointer()),this.chatSession=await this.chatSession.save(),this.onChatSaved&&this.onChatSaved(this),this.sessionId=this.chatSession?.id,this.sessionId){let t=`${window.location.origin}/chat/pro/chat/${this.sessionId}`;window.location?.pathname?.indexOf("chat/session")>-1&&(t=`${window.location.origin}/chat/session/chat/${this.sessionId}`),"modal"==this.mode&&(t=window.location.href),t=this.getInviteUrl(t),window.history.replaceState(null,null,t+window.location.search);let e={sid:this.chatSession?.id,rid:this.role?.id,name:this.role?.get("name"),message:this.chatSession?.get("messageList")?.[this.chatSession?.get("messageList")?.length-1]?.content?.slice(0,20),latest:this.chatSession?.createdAt};this.chatServ?.chatList?.length||(this.chatServ.chatList=[]);let s=this.chatServ?.chatList?.find((t=>t?.sid==e?.sid));s>-1?this.chatServ.chatList[s]=e:this.chatServ?.chatList.unshift(e)}}getInviteUrl(t){let e=new URL(t),s=Parse.User?.current()?.id;return e.searchParams.set("invite",s),e.href}genTitle(){if(this.title)return this.title;let t=this.messageList.find((t=>"user"==t.role))?.content;return"string"==typeof t&&(this.title=t?.slice(0,15)||""),"object"==typeof t&&(this.title=t?.find((t=>t?.text))?.text||""),this.title}fixMessageList(t){return t.map((t=>({role:t.role,content:t.content})))}nowStr(){let t=new Date;return`${t.getFullYear()}/${t.getMonth()+1}/${t.getDate()} ${t.getHours()}:${t.getMinutes()}:${t.getSeconds()}`}}export class FmodeChatCompletion{constructor(t,e){this.content="",this.contentBuffer=[],this.isCompleted=!1,this.indexOfList=Number(t.length),this.messages=t,this.model=e?.model||"fmode-4.5-128k"}sendCompletion(t={}){t.intTime=t?.intTime||50,t.isDirect=t?.isDirect||!1,t?.isDirect&&(t.intTime=1);let e={messages:this.messages,stream:!0,model:this.model,temperature:.5,presence_penalty:0,frequency_penalty:0};return new Observable((s=>{let i=RequestFmodeChatApi("/v1/chat/completions",e).subscribe((e=>{let o=String(e);if("data: [DONE]"==o&&(this.isCompleted=!0,t?.isDirect&&this.isCompleted&&(s.next({role:"assistant",content:this.content,complete:!0,createdAt:new Date}),i.unsubscribe(),t?.onComplete&&t.onComplete({role:"assistant",content:this.content,complete:!0,createdAt:new Date}),s.complete())),o.indexOf("data: {")>-1){let e=chunkToJson(o),n=e?.choices?.[0]?.delta?.content||"";this.contentBuffer.push(n),t?.isDirect&&(this.content+=n||"",this.isCompleted||s.next({role:"assistant",cid:e?.id,content:this.content,createdAt:new Date})),t?.isDirect||this.contentPusher||(this.contentPusher=setInterval((()=>{this.isCompleted&&0==this.contentBuffer?.length&&(s.next({role:"assistant",cid:e?.id,content:this.content,complete:!0,createdAt:new Date}),i.unsubscribe(),clearInterval(this.contentPusher),s.complete()),this.contentBuffer?.length>=0&&(this.contentBuffer?.length>0&&(this.content+=this.contentBuffer.shift()),s.next({role:"assistant",cid:e?.id,content:this.content,createdAt:new Date}))}),t?.intTime))}}))})).pipe(bufferTime(100),concatMap((t=>t)),delay(200))}}function chunkToJson(t){let e;try{e=JSON.parse(t.replaceAll("data: ",""))}catch(t){console.error(t)}return e||{}}function RequestFmodeChatApi(t,e,s="POST"){return new Observable((i=>{let o=API_BASE+t,n=`Bearer ${Parse.User.current()?.getSessionToken()||localStorage.getItem("FMODE_AI_TOKEN")}`;return e.token=n,e&&(e=JSON.stringify(e)),fetch(o,{headers:{"Content-Type":"text/plain; charset=utf-8","Cache-Control":"no-cache"},body:e||null,method:s,credentials:"omit",mode:"cors"}).then((t=>{let e="";{let s=t.body?.getReader();const o=new TextDecoder;let n=new ReadableStream({start(t){!function read(){s.read().then((({done:e,value:s})=>{if(e)return t.close(),void i.complete();t.enqueue(s),read()}))}()}}).getReader();n.read().then((function processStream({done:t,value:s}){if(t)return;!function processData(t){let s=(e+t).split("\n");if(s?.length>1){for(let t=0;t<s.length-1;t++){let e=s[t];i.next(e)}e=s[s.length-1]}}(o.decode(s)),n.read().then(processStream)}))}})).catch((t=>i.error(t))),()=>{}}))}function JsonToFormData(t){const e=new FormData;return function appendFormData(t,s=""){Array.isArray(t)?t.forEach(((t,e)=>{appendFormData(t,`${s}[${e}]`)})):"object"==typeof t&&null!==t?Object.keys(t).forEach((e=>{const i=s?`${s}.${e}`:e;appendFormData(t[e],i)})):e.append(s,t)}(t),e}
|
|
8
|
+
import{bufferTime,concatMap,Observable,delay,finalize}from"rxjs";import Parse from"parse";import{AgentPrompt}from"../../agent";import{FmodeTTS}from"../../voice/tts";import{PromptTemplate}from"@langchain/core/prompts";const API_BASE="https://server.fmode.cn/api/apig/aigc/gpt",agentPrompt=new AgentPrompt,PromptTplTalkSSMLOutputCode="talk-ssml-output-tpl",PromptTplTalkTextSSMLCode="talk-text-ssml-tpl";export function getMessageContentText(t){let e="";return"string"==typeof t&&(e=t),"object"==typeof t&&(e=t?.find((t=>t?.text))?.text||""),e}export function getMessageImageUrl(t){return"object"==typeof t?t?.find((t=>t?.image_url))?.image_url?.url||"":null}export class FmodeChat{async loadModelList(t){if(this.modelList?.length)return;let e=new Parse.Query("ChatModel");e.notEqualTo("isDeleted",!0),e.equalTo("isEnabled",!0),e.addAscending("index"),this.modelList=await e.find(),this.currentModel=t||this.modelList?.find((t=>"fmode-4.5-128k"==t.get("code")))}showAvatar(){this.avatarConfig=this.role?.get("avatarConfig"),this.avatarConfig&&(this.isAvatarShow=!0,this.avatarConfig?.image&&(this.avatarConfig.image.waiting=this.avatarConfig.image.waiting||this.role?.get("thumb")||this.role?.get("avatar"),this.avatarMode="image"),this.avatarConfig?.video&&(this.avatarConfig.video.waiting=this.avatarConfig.video.waiting,this.avatarMode="video"))}scrollToBottom(t){t=t||this.scrollComp,t?.nativeElement?.scrollHeight&&(t.nativeElement.scrollTop=t.nativeElement.scrollHeight)}constructor(t,e,s,i,o,n,a){this.ChatSession=Parse.Object.extend("ChatSession"),this.messageList=[{role:"system",content:"系统提示:AI仅供参考"}],this.latestAIResponse="",this.userInput="",this.userImage="",this.isDirect=!1,this.mode="page",this.hideShare=!1,this.hideModalSelect=!1,this.hideInputPreview=!1,this.isAvatarShow=!1,this.avatarMode="",this.isPromptModalOpen=!1,this.isPromptMessageAreaShow=!0,this.promptList=[],this.focusUserInput=()=>{},this.leftButtons=[{title:"灵感",icon:"color-wand-outline",onClick:()=>{this.isPromptModalOpen=!0},show:()=>this?.promptList?.length},{title:"角色",icon:"people-outline",onClick:()=>{this.navCtrl?.navigateRoot("/chat/pro/mask")},show:()=>!0},{title:"呼叫",icon:"call-outline",onClick:()=>{this.chatServ?.callRole(this.role)},show:()=>this?.role?.get("voiceConfig")}],this.isVoiceInputMode=!1,this.isTexting=!1,this.isTalkMode=!1,this.SSMLRoleVoice="zh-CN-XiaoxiaoNeural",this.playAnimation=t=>{console.log(t)},this.welcome=async()=>{let t=this.messageList?.filter((t=>"assistant"==t?.role));if(t?.length)return;let e=Parse.User.current(),s=await this.loadSelf("Person","userVerify"),i=await this.loadSelf("Profile","user"),o=e?.get("nickname")||i?.get("name")||e?.get("realname")||e?.get("name"),n=s?.get("name")||s?.get("userVefiry")?.get("realname")||s?.get("userVefiry")?.get("nickname");s?.get("userVerify")?.id==e?.id&&(n="您");let a=this.role.get("voiceConfig")?.welcome?.prompt;if(this.role.get("voiceConfig")?.welcome?.promptList?.length){let t=this.role.get("voiceConfig")?.welcome?.promptList;a=t[Math.floor(Math.random()*t.length)]}if(!a)return;let r=await PromptTemplate.fromTemplate(a,{templateFormat:"mustache"}).format({name:o,userName:o,personName:n,timeOfDay:this.getTimeOfDay()}),l=await this.getVoiceByContentText(r),h={role:"assistant",voice:l,content:r,complete:!0};this.voiceMap[l?.id],this.playChatVoice(this.voiceMap[l?.id]),this.messageList.push(h)},this.self={},this.voiceMap={},this.VoiceTTSMap={},this.chatServ=i,this.role=e,this.sessionId=t,this.navCtrl=o,this.ncloud=n,this.uploadServ=a,s?.id&&(this.chatSession=s,this.messageList=this.chatSession.get("messageList"),this.sessionId=s?.id),this.role?.id&&(this.voiceConfig=this.role?.get("voiceConfig"),this.voiceConfig?.autoTalk&&(this.isTalkMode=!0,this.isDirect=!0))}getTimeOfDay(){const t=(new Date).getHours();return t>=5&&t<12?"早上":t>=12&&t<14?"中午":t>=14&&t<18?"下午":"晚上"}async loadSelf(t,e){if(this.self[t])return this.self[t];let s=Parse.User.current(),i=new Parse.Query(t);return i.include(e),i.equalTo(e,s?.id),this.self[t]=await i.first(),this.self[t]}async loadTalkSystemPrompt(t){if(!this.isTalkMode)return;if(!t)return;"男"==t?.get("gender")?this.SSMLRoleVoice="zh-CN-YunyeNeural":this.SSMLRoleVoice="zh-CN-XiaoxiaoNeural",this.SSMLRoleVoice=t?.get("voiceConfig")?.voice||this.SSMLRoleVoice;let e=await agentPrompt.getFormatTpl("talk-ssml-output-tpl",{SSMLRoleVoice:this.SSMLRoleVoice}),s=t.get("prompt")||"请你扮演飞码AI的人工智能专家。";s+=e;let i={role:"user",content:s,hidden:!0},o=this.messageList?.map((t=>t?.content)).join();if(o.indexOf(s)>-1)return;let n=this.messageList?.findIndex((t=>"system"==t?.role)),a=n+1;this.messageList.splice(a,0,i)}loadRolePrompt(){let t=this.role?.get("prompt"),e={role:"user",content:t,hidden:!0};if(!t)return;let s=this.messageList?.map((t=>t?.content)).join();if(s.indexOf(t)>-1)return;let i=this.messageList?.findIndex((t=>"system"==t?.role)),o=i+1;this.messageList.splice(o,0,e)}async sendMessage(t="FmodeAiTest测试问题",e,s,i,o){if(this.scrollToBottom&&this.scrollToBottom(),this.isPromptMessageAreaShow=!1,this.loadRolePrompt(),e){let s={role:"user",content:[{type:"image_url",image_url:{url:e}},{type:"text",text:t}],complete:!0,createdAt:new Date};o&&(s.voice={id:o?.id}),this.messageList.push({role:"user",content:[{type:"image_url",image_url:{url:e}},{type:"text",text:t}],complete:!0,createdAt:new Date})}else{let e={role:"user",content:t,complete:!0,createdAt:new Date};o&&(e.voice={id:o?.id,duration:o?.duration}),this.messageList.push(e)}let n=new FmodeChatCompletion(this.fixMessageList(this.messageList),{model:this.currentModel?.get("code")||"fmode-4.5-128k"});if(this.onUserSend){if(!await this.onUserSend(this,this.messageList[this.messageList?.length-1]))return}this.userInput="",this.userImage="";let a=this.isDirect||!1;this.isTalkMode&&(a=!0);let r=n.sendCompletion({isDirect:a,onComplete:s||null}).pipe(finalize((async()=>{if(this.isTalkMode){let t=this.messageList[n.indexOfList]?.content,e=await this.getVoiceByContentText(t,i);i?.onSSMLComplete&&i?.onSSMLComplete(e),this.messageList[n.indexOfList].voice=e,this.playChatVoice(this.voiceMap[e?.id])}this.messageList[n.indexOfList].complete=!0}))).subscribe((t=>{this.messageList[n.indexOfList]=t,this.latestAIResponse=this.getContentText(t?.content);let e=this.chatSession?.get("messageList")?.length;this.messageList?.length>e&&this.saveChatSession(),t?.complete&&(this.onMessage&&this.onMessage(this,this.messageList[this.messageList?.length-1]),this.saveChatSession(),r.unsubscribe()),this.scrollToBottom&&this.scrollToBottom()}))}getVoiceByContentText(t,e,s=!1){let i=this.getContentText(t),o=new(Parse.Object.extend("ChatVoice")),n="";return this.SSMLRoleVoice=this.role?.get("voiceConfig")?.voice||this.SSMLRoleVoice,new Promise((async(t,e)=>{let resolveChatVoice=async()=>{o.set("content",i),o.set("ssml",n),o.set("role","assistant");let e=localStorage.getItem("company");e&&o.set("company",{__type:"Pointer",className:"Company",objectId:e}),Parse.User.current()?.id&&o.set("user",Parse.User.current().toPointer()),this.chatSession?.id&&o.set("session",this.chatSession?.toPointer()),o=await o.save(),this.voiceMap[o?.id]=o,t({id:o?.id})};if(0==s&&(n=`<speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" version="1.0" xml:lang="zh-CN"><voice name="${this.SSMLRoleVoice}">${i}</voice></speak>`,resolveChatVoice()),1==s){let t=await agentPrompt.getFormatTpl("talk-text-ssml-tpl",{content:i,SSMLRoleVoice:this.SSMLRoleVoice});new FmodeChatCompletion(this.fixMessageList([{role:"user",content:t}]),{model:this.currentModel?.get("code")||"fmode-4.5-128k"}).sendCompletion({isDirect:!0}).subscribe((async t=>{t?.complete&&(n=this.getContentText(t?.content),resolveChatVoice())}))}}))}getContentText(t){return"string"==typeof t?t:t?.[0]?.text||""}async initTTS(){let t=await this.ncloud.apig("voice/tts/token",{company:localStorage.getItem("company")});if(console.log(t),t?.token){return new FmodeTTS(t,this.uploadServ)}return null}stopPlayingVoice(){Object.values(this.VoiceTTSMap).forEach((t=>{t?.isPlaying&&t?.stop()}))}async playChatVoice(t,e){let s=await this.initTTS();if(s){try{this.playAnimation("talking"),s.speakAsync(t?.get("ssml"),t,{onStart:t=>{e?.onStart&&e?.onStart(t)},onLoaded:t=>{e?.onLoaded&&e?.onLoaded(t)},onStop:()=>{e?.onStop&&e?.onStop(),this.playAnimation("waiting")}})}catch(t){console.error(t)}return this.VoiceTTSMap[t.id]=s,s}return null}async saveChatSession(){if("new"==this.sessionId&&(this.chatSession=new this.ChatSession),this.chatSession.set("title",this.genTitle()),this.chatSession.set("role",this.role?.toPointer()),this.chatSession.set("messageList",this.messageList),this.chatSession.set("user",Parse.User.current()?.toPointer()),this.chatSession=await this.chatSession.save(),this.onChatSaved&&this.onChatSaved(this),this.sessionId=this.chatSession?.id,this.sessionId){let t=`${window.location.origin}/chat/pro/chat/${this.sessionId}`;window.location?.pathname?.indexOf("chat/session")>-1&&(t=`${window.location.origin}/chat/session/chat/${this.sessionId}`),"modal"==this.mode&&(t=window.location.href),t=this.getInviteUrl(t),window.history.replaceState(null,null,t+window.location.search);let e={sid:this.chatSession?.id,rid:this.role?.id,name:this.role?.get("name"),message:this.chatSession?.get("messageList")?.[this.chatSession?.get("messageList")?.length-1]?.content?.slice(0,20),latest:this.chatSession?.createdAt};this.chatServ&&!this.chatServ?.chatList?.length&&(this.chatServ.chatList=[]);let s=this.chatServ?.chatList?.find((t=>t?.sid==e?.sid));s>-1?this.chatServ.chatList[s]=e:this.chatServ?.chatList.unshift(e)}}getInviteUrl(t){let e=new URL(t),s=Parse.User?.current()?.id;return e.searchParams.set("invite",s),e.href}genTitle(){if(this.title)return this.title;let t=this.messageList.find((t=>"user"==t.role))?.content;return"string"==typeof t&&(this.title=t?.slice(0,15)||""),"object"==typeof t&&(this.title=t?.find((t=>t?.text))?.text||""),this.title}fixMessageList(t){return t.map((t=>({role:t.role,content:t.content})))}nowStr(){let t=new Date;return`${t.getFullYear()}/${t.getMonth()+1}/${t.getDate()} ${t.getHours()}:${t.getMinutes()}:${t.getSeconds()}`}}export class FmodeChatCompletion{constructor(t,e){this.content="",this.contentBuffer=[],this.isCompleted=!1,this.indexOfList=Number(t.length),this.messages=t,this.model=e?.model||"fmode-4.5-128k"}sendCompletion(t={}){t.intTime=t?.intTime||50,t.isDirect=t?.isDirect||!1,t?.isDirect&&(t.intTime=1);let e={messages:this.messages,stream:!0,model:this.model,temperature:.5,presence_penalty:0,frequency_penalty:0};return new Observable((s=>{let i=RequestFmodeChatApi("/v1/chat/completions",e).subscribe((e=>{let o=String(e);if("data: [DONE]"==o&&(this.isCompleted=!0,t?.isDirect&&this.isCompleted&&(s.next({role:"assistant",content:this.content,complete:!0,createdAt:new Date}),i.unsubscribe(),t?.onComplete&&t.onComplete({role:"assistant",content:this.content,complete:!0,createdAt:new Date}),s.complete())),o.indexOf("data: {")>-1){let e=chunkToJson(o),n=e?.choices?.[0]?.delta?.content||"";this.contentBuffer.push(n),t?.isDirect&&(this.content+=n||"",this.isCompleted||s.next({role:"assistant",cid:e?.id,content:this.content,createdAt:new Date})),t?.isDirect||this.contentPusher||(this.contentPusher=setInterval((()=>{this.isCompleted&&0==this.contentBuffer?.length&&(s.next({role:"assistant",cid:e?.id,content:this.content,complete:!0,createdAt:new Date}),i.unsubscribe(),clearInterval(this.contentPusher),s.complete()),this.contentBuffer?.length>=0&&(this.contentBuffer?.length>0&&(this.content+=this.contentBuffer.shift()),s.next({role:"assistant",cid:e?.id,content:this.content,createdAt:new Date}))}),t?.intTime))}}))})).pipe(bufferTime(100),concatMap((t=>t)),delay(200))}}function chunkToJson(t){let e;try{e=JSON.parse(t.replaceAll("data: ",""))}catch(t){console.error(t)}return e||{}}function RequestFmodeChatApi(t,e,s="POST"){return new Observable((i=>{let o=API_BASE+t,n=`Bearer ${Parse.User.current()?.getSessionToken()||localStorage.getItem("FMODE_AI_TOKEN")}`;return e.token=n,e&&(e=JSON.stringify(e)),fetch(o,{headers:{"Content-Type":"text/plain; charset=utf-8","Cache-Control":"no-cache"},body:e||null,method:s,credentials:"omit",mode:"cors"}).then((t=>{let e="";{let s=t.body?.getReader();const o=new TextDecoder;let n=new ReadableStream({start(t){!function read(){s.read().then((({done:e,value:s})=>{if(e)return t.close(),void i.complete();t.enqueue(s),read()}))}()}}).getReader();n.read().then((function processStream({done:t,value:s}){if(t)return;!function processData(t){let s=(e+t).split("\n");if(s?.length>1){for(let t=0;t<s.length-1;t++){let e=s[t];i.next(e)}e=s[s.length-1]}}(o.decode(s)),n.read().then(processStream)}))}})).catch((t=>i.error(t))),()=>{}}))}function JsonToFormData(t){const e=new FormData;return function appendFormData(t,s=""){Array.isArray(t)?t.forEach(((t,e)=>{appendFormData(t,`${s}[${e}]`)})):"object"==typeof t&&null!==t?Object.keys(t).forEach((e=>{const i=s?`${s}.${e}`:e;appendFormData(t[e],i)})):e.append(s,t)}(t),e}
|
|
9
9
|
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9haWdjL3NlcnZpY2UtZm1haS9zZXJ2aWNlLWNoYXQvY2hhdC1jbGFzcy5tanM=`
|
|
10
10
|
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* 保留所有权利 All Rights Reserved.
|
|
6
6
|
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/aigc/voice/fmode-voice.service.mjs
|
|
7
7
|
*/
|
|
8
|
-
import{Injectable}from"@angular/core";import Recorder from"recorder-core";import"recorder-core/src/engine/pcm";import"recorder-core/src/engine/wav";import"recorder-core/src/extensions/waveview";import CryptoJS from"crypto-js";import{pcmtoWav}from"./lib/pcm2wav";import{convertFrameBufferToBase64,resampleBuffer}from"./lib/resample";import{WebSpeech}from"./class-asr";import{Platform}from"@ionic/angular";import{
|
|
8
|
+
import{Injectable}from"@angular/core";import Recorder from"recorder-core";import"recorder-core/src/engine/pcm";import"recorder-core/src/engine/wav";import"recorder-core/src/extensions/waveview";import CryptoJS from"crypto-js";import{pcmtoWav}from"./lib/pcm2wav";import{convertFrameBufferToBase64,resampleBuffer}from"./lib/resample";import{WebSpeech}from"./class-asr";import{Platform}from"@ionic/angular";import{DiagnosticOriginal}from"@awesome-cordova-plugins/diagnostic";import*as i0 from"@angular/core";import*as i1 from"@ionic/angular";import*as i2 from"@awesome-cordova-plugins/diagnostic";export class FmodeVoiceService{constructor(t,e){this.platform=t,this.diagnostic=e,this.webSpeech=WebSpeech,this.isUserFinish=!1,this.recordWavBlob=null,this.recordPcmBlob=null,this.recordDuration=0,this.recordType="pcm",this.encodingType="raw",this.connStatus="",this.btnStatus="UNDEFINED",this.resultText="",this.resultTextTemp="",this.APPID="50f4a46c",this.API_SECRET="NzFlNmFhZDJjMDNkZGM3NzI0Mzg2OGNm",this.API_KEY="106ddc40dfd4b9ca6d7b47c70fada749",this.durationStr="00:00",this.duration=0,this.requestPermission()}toggleRecord(){console.log(this.btnStatus),"UNDEFINED"===this.btnStatus||"CLOSED"===this.btnStatus?this.startTalk():"CONNECTING"!==this.btnStatus&&"OPEN"!==this.btnStatus||this.finishTalk()}finishTalk(){this.isUserFinish=!0,this.onBeforeFinishTalk&&this.onBeforeFinishTalk(),this.recordStop()}async startTalk(t){this.resultText="",this.resultTextTemp="",this.onBeforeStartTalk&&this.onBeforeStartTalk(),event?.preventDefault(),await this.openWithPriviledge(),setTimeout((()=>{this.connectWebSocket()}),100),this.startCountdown(),this.onAfterStartTalk&&this.onAfterStartTalk()}cancelTalk(){this.onBeforeCancelTalk&&this.onBeforeCancelTalk(),this.recordStop(),this.iatWS?.close(),this.resultText=null,this.onAfterCancelTalk&&this.onAfterCancelTalk()}async recordStart(){this.createRecorder(),await this.openWithPriviledge(),this.recorder.start(),this.changeBtnStatus("OPEN"),this.onAfterRecordStart&&this.onAfterRecordStart()}recordStop(){return new Promise((t=>{clearInterval(this.countdownInterval),this.changeBtnStatus("CLOSED"),this.recorder?.stop((async(e,i)=>{try{this.iatWS.send(JSON.stringify({data:{status:2,format:"audio/L16;rate=16000",encoding:this.encodingType,audio:""}}))}catch(t){}let s=(window.URL||webkitURL).createObjectURL(e);console.log(e,s,"时长:"+i+"ms"),this.recordPcmBlob=e,this.recordWavBlob=await this.pcmBlobToWavBlob(e,44100),console.log("this.recordWavBlob",this.recordWavBlob),setTimeout((()=>{this.isUserFinish&&(this.onAfterFinishTalk&&this.onAfterFinishTalk(),this.isUserFinish=!1)}),2e3),this.recorder?.close(),this.recorder=null,console.log("localUrl",s),t(!0)}),(e=>{console.log("录音失败:"+e),this.recorder.close(),this.recorder=null,t(null)}))}))}playRecord(){this.playPCM(this.recordPcmBlob,44100)}async pcmBlobToWavBlob(t,e){return new Promise((i=>{let s=new FileReader;s.onload=function(t){let s=t.target.result,r=pcmtoWav(s,e,1,16);i(r)},s.readAsArrayBuffer(t)}))}async playPCM(t,e){let i=await this.pcmBlobToWavBlob(t,e),s=window.URL.createObjectURL(i),r=new Audio;r.src=s,r.play()}async playBuffers(){let t=await this.BuffersToBlob(this.buffers);this.playPCM(t,44100)}BuffersToBlob(t){let e=[];return t.forEach((t=>{t.forEach((t=>{e.push(t)}))})),new Blob([e],{type:"audio/pcm"})}splitAudioData(t){const e=1280,i=Math.ceil(t.length/e),s=[];for(let r=0;r<i;r++){const i=r*e,o=i+e,a=t.slice(i,o);s.push(a)}return s}BufferToBlob(t){return new Blob([t],{type:"audio/pcm"})}createRecorder(){this.recorder||(this.recorder=Recorder({type:this.recordType,sampleRate:44100,bitRate:16,onProcess:(t,e,i,s,r,o)=>{let a=t.length&&t[t.length-1];if(this.buffers=t,a=resampleBuffer(a,44100,16e3),this.iatWS.readyState===this.iatWS.OPEN){if(this.disableASR)return;this.iatWS.send(JSON.stringify({data:{status:1,format:"audio/L16;rate=16000",encoding:this.encodingType,audio:convertFrameBufferToBase64(a)}}))}this.waveClient?.input(t[t.length-1],e,s)}}))}async openWithPriviledge(){return console.log(this.btnStatus),await this.requestPermission(),this.createRecorder(),!!Recorder.IsOpen()||new Promise((t=>{this.recorder.open((()=>{let e=document.querySelector(".record-wave");e&&(console.log(e),Recorder.WaveView&&(this.waveClient=Recorder.WaveView({elem:".record-wave"}))),t(!0)}),((t,e)=>{console.log((e?"UserNotAllow,":"")+"无法录音:"+t)}))}))}getWebSocketUrl(){let t="wss://iat-api.xfyun.cn/v2/iat",e="iat-api.xfyun.cn",i=this.API_KEY,s=this.API_SECRET,r=(new Date).toUTCString(),o=`host: ${e}\ndate: ${r}\nGET /v2/iat HTTP/1.1`,a=CryptoJS.HmacSHA256(o,s),n=CryptoJS.enc.Base64.stringify(a);return t=`${t}?authorization=${btoa(`api_key="${i}", algorithm="hmac-sha256", headers="host date request-line", signature="${n}"`)}&date=${r}&host=${e}`,t}toBase64(t){for(var e="",i=new Uint8Array(t),s=i.byteLength,r=0;r<s;r++)e+=String.fromCharCode(i[r]);return window.btoa(e)}countTimer(){this.duration++;let t=String(parseInt(String(this.duration/60))).padStart(2,"0"),e=String((this.duration%60).toFixed(0)).padStart(2,"0"),i=t+":"+e;this.durationStr=i,this.connStatus=`录音中(${this.durationStr})`,console.log(this.duration,t,e),console.log(this.duration),console.log(i),this.onDurationStrChange&&this.onDurationStrChange(i)}startCountdown(){this.recordDuration=0,this.durationInterval&&clearInterval(this.durationInterval),this.countdownInterval=setInterval((()=>{this.recordDuration+=100}),100),this.now=new Date,this.duration=0,this.countdownInterval&&clearInterval(this.countdownInterval),this.countdownInterval=setInterval((()=>{this.countTimer()}),1e3)}changeBtnStatus(t){this.btnStatus=t,"CONNECTING"===t?this.connStatus="建立连接中":"OPEN"===t||("CLOSING"===t?this.connStatus="关闭连接中":"CLOSED"===t&&(this.connStatus="开始录音"))}renderResult(t){let e=JSON.parse(t);if(e.data&&e.data.result){let t=e.data.result,i="",s=t.ws;for(let t=0;t<s.length;t++)i+=s[t].cw[0].w,console.log(i);t.pgs?("apd"===t.pgs&&(this.resultText=this.resultTextTemp),this.resultTextTemp=this.resultText+i):this.resultText=this.resultText+i,this.resultTextTemp||this.resultText,console.log("diff temp",this.resultTextTemp),console.log("diff result",this.resultText),this.onInputChange&&this.onInputChange(this.getUserInput())}0===e.code&&2===e.data.status&&this.iatWS.close(),0!==e.code&&(this.iatWS.close(),console.error(e))}getUserInput(){return""+(this.resultTextTemp||this.resultText)}connectWebSocket(){console.log("connectWebSocket");const t=this.getWebSocketUrl();if("WebSocket"in window)this.iatWS=new WebSocket(t);else if(!("MozWebSocket"in window))return void alert("浏览器不支持WebSocket");console.log("connectWebSocket",this.btnStatus),this.changeBtnStatus("CONNECTING"),this.iatWS.onopen=t=>{this.recordStart();var e={common:{app_id:this.APPID},business:{language:"zh_cn",domain:"iat",accent:"mandarin",vad_eos:5e3,dwa:"wpgs"},data:{status:0,format:"audio/L16;rate=16000",encoding:this.encodingType}};this.iatWS.send(JSON.stringify(e))},this.iatWS.onmessage=t=>{console.log("onmessage"+this.resultText),this.renderResult(t.data)},this.iatWS.onerror=t=>{console.error("error",t),this.recordStop(),this.changeBtnStatus("CLOSED")},this.iatWS.onclose=async t=>{console.log("onclose"+this.resultText),this.reconnectWebsocket()}}async reconnectWebsocket(){this.isUserFinish||this.connectWebSocket()}isCapacitor(){return this.platform.is("capacitor")||this.platform.is("cordova")}async requestPermission(){if(this.isCapacitor())try{await this.requestStoagePermission(),await this.requestCameraPermission(),await this.requestMicPermission(),await this.requestRecordAudioPermission()}catch(t){console.error(t)}}async requestRecordAudioPermission(){let t=await this.diagnostic.requestRuntimePermissions([this.diagnostic.permission.RECORD_AUDIO]);console.log("record permission request:",t)}async requestMicPermission(){let t=await this.diagnostic.isMicrophoneAuthorized();if(console.log("permisson_MIC:",t),!t){await this.diagnostic.requestMicrophoneAuthorization()}}async requestStoagePermission(){let t=await this.diagnostic.isExternalStorageAuthorized();if(console.log("permisson_STORAGE:",t),!t){await this.diagnostic.requestExternalStorageAuthorization()}}async requestCameraPermission(){let t=await this.diagnostic.isCameraAuthorized();if(console.log("permisson_Camera:",t),!t){await this.diagnostic.requestCameraAuthorization()}}static{this.ɵfac=i0.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:FmodeVoiceService,deps:[{token:i1.Platform},{token:i2.DiagnosticOriginal}],target:i0.ɵɵFactoryTarget.Injectable})}static{this.ɵprov=i0.ɵɵngDeclareInjectable({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:FmodeVoiceService,providedIn:"root"})}}i0.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:FmodeVoiceService,decorators:[{type:Injectable,args:[{providedIn:"root"}]}],ctorParameters:()=>[{type:i1.Platform},{type:i2.DiagnosticOriginal}]});
|
|
9
9
|
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9haWdjL3ZvaWNlL2Ztb2RlLXZvaWNlLnNlcnZpY2UubWpz`
|
|
10
10
|
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* 保留所有权利 All Rights Reserved.
|
|
6
6
|
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/aigc/voice/stream.player.mjs
|
|
7
7
|
*/
|
|
8
|
-
import{PushAudioOutputStreamCallback}from"microsoft-cognitiveservices-speech-sdk
|
|
8
|
+
import{PushAudioOutputStreamCallback}from"microsoft-cognitiveservices-speech-sdk";import{Subject}from"rxjs";import{bufferWhen,filter,takeUntil}from"rxjs/operators";export class FmPushAudioOutputStreamCallback extends PushAudioOutputStreamCallback{constructor(){super(),this.audioDataSubject=new Subject,this.playedSubject=new Subject,this.isPlaying=!1,this.isClosed=!1,this.audioBufferQueue=[],this.maxBufferSize=10,this.writeCount=0,this.audioContext=new(window.AudioContext||window.webkitAudioContext),this.audioDataSubject.pipe(bufferWhen((()=>this.playedSubject)),takeUntil(this.audioDataSubject.pipe(filter((()=>this.isClosed))))).subscribe((t=>{this.playAudio(t)}))}async write(t){this.writeCount++,10==this.writeCount&&this.playedSubject.next(!0),this.audioDataSubject.next(t)}async playAudio(t){this.isPlaying=!0;const e=this.mergeArrayBuffers(t);let i;try{i=await this.audioContext.decodeAudioData(e)}catch(t){}if(i){const t=this.audioContext.createBufferSource();t.buffer=i,t.connect(this.audioContext.destination),t.start(),await new Promise((e=>{t.onended=e})),this.playedSubject.next(!0)}this.isPlaying=!1}mergeArrayBuffers(t){const e=t.reduce(((t,e)=>t+e.byteLength),0),i=new Uint8Array(e);let s=0;for(const e of t){const t=new Uint8Array(e);i.set(t,s),s+=t.length}return i.buffer}async stop(){this.isClosed=!0,this.audioDataSubject&&this.audioDataSubject.unsubscribe(),this.playedSubject&&this.playedSubject.unsubscribe(),this.audioContext&&this.audioContext.close()}async close(){console.log("close 数据加载完成"),this.isClosed=!0}}
|
|
9
9
|
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9haWdjL3ZvaWNlL3N0cmVhbS5wbGF5ZXIubWpz`
|
|
10
10
|
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* 保留所有权利 All Rights Reserved.
|
|
6
6
|
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/aigc/voice/tts/fmode-tts-class.mjs
|
|
7
7
|
*/
|
|
8
|
-
import{SpeechSynthesizer}from"microsoft-cognitiveservices-speech-sdk
|
|
8
|
+
import{SpeechSynthesizer}from"microsoft-cognitiveservices-speech-sdk";import{SpeechConfig}from"microsoft-cognitiveservices-speech-sdk";import{ResultReason}from"microsoft-cognitiveservices-speech-sdk";import{AudioConfig}from"microsoft-cognitiveservices-speech-sdk";import Parse from"parse";import{AudioPlayer}from"../audio.player";import{FmPushAudioOutputStreamCallback}from"../stream.player";export class FmodeTTS{stop(){this.audioPlayer&&this.audioPlayer?.stop(),this.audioStream&&this.audioStream?.stop()}constructor(e,t){this.isPlaying=!1,this.uploadServ=t,this.subscriptionKey=e?.subscriptionKey,this.authorizationToken=e?.token,this.region=e?.region,this.subscriptionKey&&(this.speechConfig=SpeechConfig.fromSubscription(this.subscriptionKey,this.region)),this.authorizationToken&&(this.speechConfig=SpeechConfig.fromAuthorizationToken(this.authorizationToken,this.region)),this.audioStream=new FmPushAudioOutputStreamCallback,this.audioConfig=AudioConfig.fromStreamOutput(this.audioStream),this.synthesizer=new SpeechSynthesizer(this.speechConfig,this.audioConfig),this.audioPlayer=AudioPlayer.getInstance()}extractTextFromXML(e){const t=/>([^<]+)</g;let o,i=[];for(;null!==(o=t.exec(e));){const e=o[1].trim();e&&i.push(e)}return i.join(" ")}extractSSMLContent(e){var t=e.match(/<speak.*?<\/speak>/s);return t?t[0]:e}async speakAsync(e,t,o){if(!t){let o=Parse.Object.extend("ChatVoice");(t=new o).set("ssml",e),t.set("content",this.extractTextFromXML(e));let i=localStorage.getItem("company");i&&t.set("company",{__type:"Pointer",className:"Company",objectId:i}),Parse.User.current()?.id&&t.set("user",Parse.User.current().toPointer())}if(!t?.get("voiceFile")){let o=[];t?.get("content")&&o.push({content:t?.get("content")}),e&&o.push({ssml:e});let i=Parse.Query.fromJSON("ChatVoice",{include:"voiceFile",where:{$or:o}}),s=await i.first();t.set("voiceFile",s?.get("voiceFile"))}return t?.get("voiceFile")?(this.playAudioData(t?.get("voiceFile")?.get("url"),t,o),t):(e=this.extractSSMLContent(e),this.isPlaying=!0,new Promise(((i,s)=>{const n=Date.now();let a="speakTextAsync";e?.indexOf("<")>-1&&(a="speakSsmlAsync"),e=this.fixMarkdownChar(e),this.eventMap?.onSpeakBefore&&this.eventMap?.onSpeakBefore(),this.synthesizer[a](e,(e=>{if(console.log(e),e.reason===ResultReason.SynthesizingAudioStarted&&(this.isPlaying=!0),e.reason===ResultReason.SynthesizingAudioCompleted){this.eventMap?.onAudioCompleted&&this.eventMap?.onAudioCompleted();const s=Date.now();let a=e?.audioData;t.set("duration",Number(e?.audioDuration)/1e4),this.playAudioData(a,t,o),console.log(`Audio synthesis finished. Duration: ${s-n} ms`),setTimeout((()=>{this.isPlaying=!1,o?.onStop()&&o?.onStop()}),2e3),i(t)}else s(`Speech synthesis failed. Reason: ${e.errorDetails}`)}),(e=>{s(`Error occurred during synthesis: ${e}`)}))})))}onBreak(e){}fixMarkdownChar(e){return e.replaceAll("*","")}async playAudioData(e,t,o){let i;if(console.log("audioData",e),!(e?.indexOf&&e?.indexOf("http")>=-1)){let o=new Blob([e],{type:"audio/wav"});return i=URL.createObjectURL(o),void this.uploadAndSaveVoice(o,t)}i=e;let s=this.audioPlayer;o?.onStart&&o?.onStart(t),this.isPlaying=!0,s.setAudioEvent("onloadeddata",(()=>{let e=1e3*s.duration;console.log("duration",e),t?.get("duration")||(t?.set("duration",e),t?.save()),o?.onLoaded&&o?.onLoaded(s)})),console.log("event setting"),s.setAudioEvent("onabort",(()=>{this.isPlaying=!1,o?.onStop&&o?.onStop()})),s.setAudioEvent("onerror",(()=>{this.isPlaying=!1,o?.onStop&&o?.onStop()})),s.setAudioEvent("onpause",(()=>{this.isPlaying=!1,o?.onStop&&o?.onStop()})),s.setAudioEvent("onended",(()=>{this.isPlaying=!1,o?.onStop&&o?.onStop()})),s.setAudioEvent("onclose",(()=>{this.isPlaying=!1,o?.onStop&&o?.onStop()})),console.log("playAudio",i);let playAudio=()=>{s.play(i).then((()=>{})).catch((()=>{setTimeout((()=>{console.log("playAudio"),playAudio()}),200)}))};playAudio()}async uploadAndSaveVoice(e,t){if(console.log("blob",e),this.uploadServ){let o=t?.id||this.uploadServ?.genMd5(t?.get("content")||t?.get("ssml")),i=new Date,s=o+i.getFullYear()+(i.getMonth()+1)+i.getDate()+i.getHours()+i.getMinutes()+i.getSeconds()+".wav",n=new File([e],s,{type:"audio/wav"}),a=await this.uploadServ.upload(n,(e=>{console.log(e)})),r={__type:"Pointer",className:"Attachment",objectId:a?.id};return r?.objectId&&(t.set("voiceFile",r),t=await t.save()),a?.url}return null}}
|
|
9
9
|
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9haWdjL3ZvaWNlL3R0cy9mbW9kZS10dHMtY2xhc3MubWpz`
|
|
10
10
|
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* 保留所有权利 All Rights Reserved.
|
|
6
6
|
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/storage/service-upload/nova-upload.service.mjs
|
|
7
7
|
*/
|
|
8
|
-
import{DatePipe}from"@angular/common";import{Injectable}from"@angular/core";import{Platform}from"@ionic/angular";import{Camera,CameraResultType,CameraSource}from"@capacitor/camera";import{Capacitor}from"@capacitor/core";import{Filesystem}from"@capacitor/filesystem";import{FilesystemWeb}from"@capacitor/filesystem/dist/esm/web.js";import*as qiniu from"qiniu-js";import Parse from"parse";import{
|
|
8
|
+
import{DatePipe}from"@angular/common";import{Injectable}from"@angular/core";import{Platform}from"@ionic/angular";import{Camera,CameraResultType,CameraSource}from"@capacitor/camera";import{Capacitor}from"@capacitor/core";import{Filesystem}from"@capacitor/filesystem";import{FilesystemWeb}from"@capacitor/filesystem/dist/esm/web.js";import*as qiniu from"qiniu-js";import Parse from"parse";import{DiagnosticOriginal}from"@awesome-cordova-plugins/diagnostic";import CryptoJS from"crypto-js";import{MediaCapture}from"@awesome-cordova-plugins/media-capture";import{calcFileMd5}from"./util-file-md5";import*as i0 from"@angular/core";import*as i1 from"@ionic/angular";import*as i2 from"@awesome-cordova-plugins/diagnostic";export class NovaUploadService{constructor(e,i){this.platform=e,this.diagnostic=i,this.maxSize=5242880,this.getUptoken(!0),this.requestPermission(),this.queryDomain()}async upload(e,i){let t,a=e.type,o=e.name?.split("."),r=o[o.length-1];try{t=await calcFileMd5(e)}catch(e){}let n,s,l=this.fileToBlob(e);return n=a.indexOf("image")>-1?await this.saveQiniuImageFile(l,r,null,i):await this.saveQiniuMediaFile(e,l,null,i),n.md5=t,n?.url?.indexOf("undefined")>-1&&(n.url=(this.qiniuDomain||"https://file-cloud.fmode.cn/")+n.url.replace("undefined/","")),n?.url&&(s=await this.saveAttachment(n,this.qiniuDomain,null,this.getCompanyId())),s?.id&&(n.id=s?.id),n}isCapacitor(){return this.platform.is("capacitor")||this.platform.is("cordova")}async requestPermission(){this.isCapacitor()&&(await this.requestStoagePermission(),await this.requestCameraPermission())}async requestStoagePermission(){let e=await this.diagnostic.isExternalStorageAuthorized();if(console.log("permisson_STORAGE:",e),!e){await this.diagnostic.requestExternalStorageAuthorization()}}async requestCameraPermission(){let e=await this.diagnostic.isCameraAuthorized();if(console.log("permisson_Camera:",e),!e){await this.diagnostic.requestCameraAuthorization()}}async getUptoken(e=!1){if(console.log("getUptoken"),this.qiniuConf||e)try{console.log(this.getCompanyId());let e=await Parse.Cloud.run("qiniu_uptoken",{company:this.getCompanyId()});console.log(e),this.qiniuConf=e}catch(e){console.error(e)}}genFileKey(e,i){let t=new Date,a=new DatePipe("en");return i||(i=this.getCompanyId()),i+"/"+a.transform(t,"yMMdd")+"/"+String(e.id).substr(20,6)+a.transform(t,"hhmmssSSS")+/\.[^\.]+/.exec(e.name)}getCompanyId(){if(this.company)return this.company;return localStorage.getItem("company")}async queryDomain(){let e=new Parse.Query("Company"),i=await e.get(this.getCompanyId());i.get("configQiniu")&&i.get("configQiniu").domain?(console.log(i.get("configQiniu").domain),this.qiniuDomain=i.get("configQiniu").domain):this.qiniuDomain="https://file-cloud.fmode.cn"}async saveAttachment(e,i,t,a){let o=e.url;o.startsWith("http")||(o=i+o),o=o.replace(/undefined\//,""),a||(a=localStorage.getItem("company"));let r=Parse.User.current(),n=new Parse.Query("Attachment");n.equalTo("url",o);let s=await n.first();if(s&&s.id)return console.error("该文件已存在,无需重复上传"),s;return s=new(Parse.Object.extend("Attachment")),s.set("size",e.size),s.set("url",o),s.set("name",e.name),s.set("mime",e.type),s.set("md5",e?.md5),r?.id&&s.set("user",r.toPointer()),a&&s.set("company",{__type:"Pointer",className:"Company",objectId:localStorage.getItem("company")}),t&&s.set("category",{__type:"Pointer",className:"Category",objectId:t}),await s.save()}async captureVideo(e){if(this.qiniuConf=e,!this.isCapacitor())return;let i=await this.cameraCaptureVideoFile(),t=await this.getMediaFileDataString(i);return await this.saveQiniuMediaFile(i,t)}async cameraCaptureVideoFile(){let e=MediaCapture,i=await e.captureVideo({limit:1});return i?.length>0?i[0]:null}async getMediaFileDataString(e){new FilesystemWeb,e.fullPath.replaceAll("///","//");let i=await Filesystem.stat({path:e.fullPath}),t=Capacitor.convertFileSrc(i.uri),a=await fetch(t),o=await a.blob();if(console.log(o.size),console.log(JSON.stringify(i)),console.log(JSON.stringify(a)),console.log(JSON.stringify(Object.keys(a))),o)return o;throw"读取文件失败"}async takePicture(e){if(this.qiniuConf=e,!this.isCapacitor())return;await this.getUptoken();let i=await this.cameraTakePictureDataUrl();if(!i?.dataUrl)return;let t=await this.base64ToBlob(i?.dataUrl),a=await this.saveQiniuImageFile(t,i?.format);return console.log(JSON.stringify(a)),a}async cameraTakePictureDataUrl(){if(!this.isCapacitor())return;return await Camera.getPhoto({quality:90,allowEditing:!1,source:CameraSource.Camera,resultType:CameraResultType.DataUrl})}async saveQiniuImageFile(e,i,t,a){let o=this.maxSize;if(e.size>o)throw await console.log("照片过大,超出限制5MB"),"超出文件大小";let r=new DatePipe("en").transform(new Date,"yyyyMMddHHmmss"),n=`${r}.${i}`,s=`image/${i}`,l={fname:n,params:{},mimeType:"image/*"},c={useCdnDomain:!0,forceDirect:!0};console.log(this.qiniuConf);let m=this.genFileKey({id:r,name:n});return console.log("图片上传前"),new Promise(((i,t)=>{console.log("进入了上传"),qiniu.upload(e,m,this.qiniuConf?.uptoken,l,c).subscribe({next:e=>{console.log(e),a&&a(e)},error:async e=>{console.log(e)},complete:t=>{console.log("上传完成"),console.log(`${this.qiniuConf?.domain}${t.key}`),t.url=`${this.qiniuConf?.domain}${t.key}`,t.name=n,t.type=s,t.size=e.size,i(t)}})}))}async saveQiniuMediaFile(e,i,t,a){let o=e.name,r=e.type;if(e.size>104857600)throw console.log("视频过大,超出限制100MB"),"超出文件大小";let n=new DatePipe("en").transform(new Date,"yyyyMMddHHmmss"),s={fname:o,params:{},mimeType:r},l={useCdnDomain:!0,forceDirect:!0},c=this.genFileKey({id:n,name:o});return console.log("图片上传前"),console.log(e.name,i.size),console.log(i.size),console.log(i.size/1024/1024),new Promise(((t,o)=>{console.log("进入了上传"),qiniu.upload(i,c,this.qiniuConf?.uptoken,s,l).subscribe({next:e=>{console.log("主要用来展示进度"),a&&a(e),console.log(JSON.stringify(e))},error:async e=>{console.log("上传失败"),console.log(JSON.stringify(e))},complete:i=>{console.log("上传完成"),console.log(JSON.stringify(i)),e.key=i.key,console.log(e.type),e.url=`${this.qiniuConf?.domain}${i.key}`,console.log(e.url),t(e)}})}))}async base64ToBlobType(e,i){let t=await fetch(`data:${i};base64,${e}`);return await t.blob()}async base64ToBlob(e){let i=await fetch(e);return await i.blob()}fileToBlob(e){const i=e.slice(0,e.size,e.type);return new Blob([i],{type:e.type})}genMd5(e){return CryptoJS.MD5(e).toString()}static{this.ɵfac=i0.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:NovaUploadService,deps:[{token:i1.Platform},{token:i2.DiagnosticOriginal}],target:i0.ɵɵFactoryTarget.Injectable})}static{this.ɵprov=i0.ɵɵngDeclareInjectable({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:NovaUploadService,providedIn:"root"})}}i0.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:NovaUploadService,decorators:[{type:Injectable,args:[{providedIn:"root"}]}],ctorParameters:()=>[{type:i1.Platform},{type:i2.DiagnosticOriginal}]});
|
|
9
9
|
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9zdG9yYWdlL3NlcnZpY2UtdXBsb2FkL25vdmEtdXBsb2FkLnNlcnZpY2UubWpz`
|
|
10
10
|
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* 保留所有权利 All Rights Reserved.
|
|
6
6
|
* /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/storage/storage.module.mjs
|
|
7
7
|
*/
|
|
8
|
-
import{NgModule}from"@angular/core";import{CommonModule}from"@angular/common";import{HwobsManagerComponent}from"./comp-hwobs-manager/hwobs-manager.component";import{IonicModule}from"@ionic/angular";import{
|
|
8
|
+
import{NgModule}from"@angular/core";import{CommonModule}from"@angular/common";import{HwobsManagerComponent}from"./comp-hwobs-manager/hwobs-manager.component";import{IonicModule}from"@ionic/angular";import{DiagnosticOriginal}from"@awesome-cordova-plugins/diagnostic";import{NovaUploadService}from"./service-upload";import*as i0 from"@angular/core";import*as i1 from"@ionic/angular";export class FmodeStorgeModule{static{this.ɵfac=i0.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:FmodeStorgeModule,deps:[],target:i0.ɵɵFactoryTarget.NgModule})}static{this.ɵmod=i0.ɵɵngDeclareNgModule({minVersion:"14.0.0",version:"17.3.12",ngImport:i0,type:FmodeStorgeModule,imports:[CommonModule,i1.IonicModule,HwobsManagerComponent],exports:[HwobsManagerComponent]})}static{this.ɵinj=i0.ɵɵngDeclareInjector({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:FmodeStorgeModule,providers:[DiagnosticOriginal,NovaUploadService],imports:[CommonModule,IonicModule.forRoot({mode:"ios"}),HwobsManagerComponent]})}}i0.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"17.3.12",ngImport:i0,type:FmodeStorgeModule,decorators:[{type:NgModule,args:[{declarations:[],imports:[CommonModule,IonicModule.forRoot({mode:"ios"}),HwobsManagerComponent],exports:[HwobsManagerComponent],providers:[DiagnosticOriginal,NovaUploadService]}]}]});
|
|
9
9
|
var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9zdG9yYWdlL3N0b3JhZ2UubW9kdWxlLm1qcw==`
|
|
10
10
|
|