mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Fix tts try on ios (#8292)
This commit is contained in:
parent
9d82ce8ab4
commit
da3f911deb
@ -141,7 +141,10 @@ export class DialogTryTts extends LitElement {
|
|||||||
this._target = target;
|
this._target = target;
|
||||||
|
|
||||||
if (target === "browser") {
|
if (target === "browser") {
|
||||||
this._playBrowser(message);
|
// We create the audio element here + do a play, because iOS requires it to be done by user action
|
||||||
|
const audio = new Audio();
|
||||||
|
audio.play();
|
||||||
|
this._playBrowser(message, audio);
|
||||||
} else {
|
} else {
|
||||||
this.hass.callService("tts", "cloud_say", {
|
this.hass.callService("tts", "cloud_say", {
|
||||||
entity_id: target,
|
entity_id: target,
|
||||||
@ -150,7 +153,7 @@ export class DialogTryTts extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _playBrowser(message: string) {
|
private async _playBrowser(message: string, audio: HTMLAudioElement) {
|
||||||
this._loadingExample = true;
|
this._loadingExample = true;
|
||||||
|
|
||||||
const language = this._params!.defaultVoice[0];
|
const language = this._params!.defaultVoice[0];
|
||||||
@ -173,13 +176,17 @@ export class DialogTryTts extends LitElement {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const audio = new Audio(url);
|
audio.src = url;
|
||||||
audio.addEventListener("canplaythrough", () => {
|
audio.addEventListener("canplaythrough", () => {
|
||||||
audio.play();
|
audio.play();
|
||||||
});
|
});
|
||||||
audio.addEventListener("playing", () => {
|
audio.addEventListener("playing", () => {
|
||||||
this._loadingExample = false;
|
this._loadingExample = false;
|
||||||
});
|
});
|
||||||
|
audio.addEventListener("error", () => {
|
||||||
|
showAlertDialog(this, { title: "Error playing audio." });
|
||||||
|
this._loadingExample = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static get styles(): CSSResult[] {
|
static get styles(): CSSResult[] {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user