File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed
Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -31,8 +31,8 @@ export class MenuPage implements OnInit, OnDestroy {
3131 public verbsStateService : VerbsStateService ,
3232 public settingsStateService : SettingsStateService ,
3333 public modalController : ModalController ,
34- private audioService : AudioService ,
3534 public appTranslateService : AppTranslateService ,
35+ public audioService : AudioService ,
3636 ) { }
3737
3838 ngOnInit ( ) {
@@ -62,11 +62,7 @@ export class MenuPage implements OnInit, OnDestroy {
6262 }
6363
6464 reproduceSound ( item : ItemWithFilesModel | VerbWithFilesModel ) : void {
65- if ( item . audio ) {
66- this . audioService . playAudioFile ( item . audio ) ;
67- } else {
68- speechSynthesis . speak ( new SpeechSynthesisUtterance ( item . text ) ) ;
69- }
65+ this . audioService . reproduceSound ( item ) ;
7066 }
7167
7268 changeLang ( lang : string ) {
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import { Injectable } from '@angular/core';
22import { RecordingData , VoiceRecorder } from 'capacitor-voice-recorder' ;
33import { BehaviorSubject , Observable } from 'rxjs' ;
44import { FileData } from '../models/file-data.model' ;
5+ import { ItemWithFilesModel } from '../models/item-with-files.model' ;
6+ import { VerbWithFilesModel } from '../models/verb-with-files.model' ;
57
68// doc: https://www.npmjs.com/package/capacitor-voice-recorder
79
@@ -68,6 +70,15 @@ export class AudioService {
6870 return this . playAudio ( audioRef ) ;
6971 }
7072
73+ reproduceSound ( item : ItemWithFilesModel | VerbWithFilesModel ) {
74+ this . stopAudio ( ) ;
75+ if ( item . audio ) {
76+ this . playAudioFile ( item . audio ) ;
77+ } else {
78+ speechSynthesis . speak ( new SpeechSynthesisUtterance ( item . text ) ) ;
79+ }
80+ }
81+
7182 stopAudio ( ) : void {
7283 if ( this . currentAudio ) {
7384 this . currentAudio . pause ( ) ;
You can’t perform that action at this time.
0 commit comments