Voice wizard: Use test message in tts language (#22882)

* Voice wizard: Use test message in tts language

* catch none existing lang
This commit is contained in:
Bram Kragten 2024-11-20 16:09:48 +01:00 committed by GitHub
parent 995155696f
commit b7ef633a3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 5 deletions

View File

@ -24,6 +24,7 @@ import "../../panels/lovelace/entity-rows/hui-select-entity-row";
import type { HomeAssistant } from "../../types";
import { AssistantSetupStyles } from "./styles";
import { STEP } from "./voice-assistant-setup-dialog";
import { getTranslation } from "../../util/common-translation";
@customElement("ha-voice-assistant-setup-step-success")
export class HaVoiceAssistantSetupStepSuccess extends LitElement {
@ -213,8 +214,24 @@ export class HaVoiceAssistantSetupStepSuccess extends LitElement {
});
}
private _testTts() {
this._announce("Hello, how can I help you?");
private async _testTts() {
const [pipeline] = await this._getPipeline();
if (!pipeline) {
return;
}
if (pipeline.language !== this.hass.locale.language) {
try {
const result = await getTranslation(null, pipeline.language, false);
this._announce(result.data["ui.dialogs.tts-try.message_example"]);
return;
} catch (e) {
// ignore fallback to user language
}
}
this._announce(this.hass.localize("ui.dialogs.tts-try.message_example"));
}
private async _announce(message: string) {

View File

@ -135,14 +135,15 @@ export function getLocalLanguage() {
export async function getTranslation(
fragment: string | null,
language: string
language: string,
fallback = true
) {
const metadata = translationMetadata.translations[language];
if (!metadata?.hash) {
if (language !== "en") {
if (fallback && language !== "en") {
return getTranslation(fragment, "en");
}
throw new Error("Language en is not found in metadata");
throw new Error(`Language '${language}' is not found in metadata`);
}
// nl-abcd.jon or logbook/nl-abcd.json