From d31839908c7710d645d9203f89f8fa8dad12723a Mon Sep 17 00:00:00 2001 From: Thomas Kemmer Date: Mon, 25 Mar 2024 23:17:09 +0100 Subject: [PATCH] Move voice selection to seperate page. --- src/app/settings/index.ts | 3 ++- src/app/settings/settings.module.ts | 6 +++++ src/app/settings/settings.page.html | 9 +++---- src/app/settings/settings.page.ts | 32 ++++------------------- src/app/settings/voice.page.html | 24 +++++++++++++++++ src/app/settings/voice.page.ts | 40 +++++++++++++++++++++++++++++ 6 files changed, 80 insertions(+), 34 deletions(-) create mode 100644 src/app/settings/voice.page.html create mode 100644 src/app/settings/voice.page.ts diff --git a/src/app/settings/index.ts b/src/app/settings/index.ts index bd7eacb6..87806fda 100644 --- a/src/app/settings/index.ts +++ b/src/app/settings/index.ts @@ -4,4 +4,5 @@ export * from './about.page'; export * from './logging.page'; export * from './licenses.page'; export * from './connection.page'; -export * from './notifications.page'; \ No newline at end of file +export * from './notifications.page'; +export * from './voice.page'; \ No newline at end of file diff --git a/src/app/settings/settings.module.ts b/src/app/settings/settings.module.ts index 29117fe2..18c7205c 100644 --- a/src/app/settings/settings.module.ts +++ b/src/app/settings/settings.module.ts @@ -14,6 +14,7 @@ import { LoggingMenu } from './logging.menu'; import { LoggingPage } from './logging.page'; import { NotificationsPage } from './notifications.page'; import { SettingsPage } from './settings.page'; +import { VoicePage } from './voice.page'; const routes: Routes = [ { @@ -39,6 +40,10 @@ const routes: Routes = [ { path: 'notifications', component: NotificationsPage + }, + { + path: 'voice', + component: VoicePage } ]; @@ -50,6 +55,7 @@ const routes: Routes = [ LoggingMenu, LoggingPage, NotificationsPage, + VoicePage, SettingsPage ], exports: [ diff --git a/src/app/settings/settings.page.html b/src/app/settings/settings.page.html index 2a493bbf..092412d0 100644 --- a/src/app/settings/settings.page.html +++ b/src/app/settings/settings.page.html @@ -12,7 +12,7 @@ - + @@ -25,11 +25,8 @@ Slovak - - - Default - {{v.name}} - + + Voice Connection diff --git a/src/app/settings/settings.page.ts b/src/app/settings/settings.page.ts index b3c76bdd..8112a583 100644 --- a/src/app/settings/settings.page.ts +++ b/src/app/settings/settings.page.ts @@ -1,7 +1,5 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; -import { TranslateService } from '@ngx-translate/core'; - import { AboutPage } from './about.page'; import { ConnectionPage } from './connection.page'; import { LicensesPage } from './licenses.page'; @@ -15,24 +13,16 @@ import { I18nAlertService, SpeechService } from '../services'; templateUrl: 'settings.page.html' }) export class SettingsPage implements OnDestroy, OnInit { - aboutPage = AboutPage; - connectionPage = ConnectionPage; - licensesPage = LicensesPage; - loggingPage = LoggingPage; - notificationsPage = NotificationsPage; options = new Options(); - voices = []; - private subscription: any; - constructor(private alert: I18nAlertService, private settings: AppSettings, private speech: SpeechService, private translate: TranslateService) {} + constructor(private alert: I18nAlertService, private settings: AppSettings, private speech: SpeechService) {} ngOnInit() { this.subscription = this.settings.getOptions().subscribe(options => { this.options = options; - this.updateVoices(); }); } @@ -53,27 +43,15 @@ export class SettingsPage implements OnDestroy, OnInit { }); } - async update() { - await this.updateVoices(); - return this.settings.setOptions(this.options); - } - - async updateVoices() { + async updateLanguage() { if (this.options.language) { - this.voices = await this.speech.getVoices(this.options.language); - if (!this.voices.find(v => v.identifier == this.options.voice)) { + let voices = await this.speech.getVoices(this.options.language); + if (!voices.find(v => v.identifier == this.options.voice)) { this.options.voice = ""; } } else { - this.voices = []; this.options.voice = ""; } - } - - async updateAndGreet() { - await this.update(); - // TODO: trigger when voice is selected - const greeting = this.translate.instant("notifications.greeting"); - this.speech.speak(greeting); + return this.settings.setOptions(this.options); } } diff --git a/src/app/settings/voice.page.html b/src/app/settings/voice.page.html new file mode 100644 index 00000000..ed959436 --- /dev/null +++ b/src/app/settings/voice.page.html @@ -0,0 +1,24 @@ + + + + + + + Voice + + + + + + + + + Default + {{v.name}} + + + + Test + + + diff --git a/src/app/settings/voice.page.ts b/src/app/settings/voice.page.ts new file mode 100644 index 00000000..60dec0cd --- /dev/null +++ b/src/app/settings/voice.page.ts @@ -0,0 +1,40 @@ +import { Component, OnDestroy } from '@angular/core'; + +import { TranslateService } from '@ngx-translate/core'; + +import { AppSettings, Options } from '../app-settings'; +import { SpeechService } from '../services'; + + +@Component({ + templateUrl: 'voice.page.html' +}) +export class VoicePage implements OnDestroy { + + options = new Options(); + + voices = []; + + private subscription: any; + + constructor(private settings: AppSettings, private speech: SpeechService, private translate: TranslateService) {} + + ngOnInit() { + this.subscription = this.settings.getOptions().subscribe(options => { + this.options = options; + }); + } + + ngOnDestroy() { + this.subscription.unsubscribe(); + } + + async update() { + return this.settings.setOptions(this.options); + } + + async test() { + const greeting = this.translate.instant("notifications.greeting"); + this.speech.speak(greeting); + } +}