mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +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;
|
||||
|
||||
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 {
|
||||
this.hass.callService("tts", "cloud_say", {
|
||||
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;
|
||||
|
||||
const language = this._params!.defaultVoice[0];
|
||||
@ -173,13 +176,17 @@ export class DialogTryTts extends LitElement {
|
||||
});
|
||||
return;
|
||||
}
|
||||
const audio = new Audio(url);
|
||||
audio.src = url;
|
||||
audio.addEventListener("canplaythrough", () => {
|
||||
audio.play();
|
||||
});
|
||||
audio.addEventListener("playing", () => {
|
||||
this._loadingExample = false;
|
||||
});
|
||||
audio.addEventListener("error", () => {
|
||||
showAlertDialog(this, { title: "Error playing audio." });
|
||||
this._loadingExample = false;
|
||||
});
|
||||
}
|
||||
|
||||
static get styles(): CSSResult[] {
|
||||
|
Loading…
x
Reference in New Issue
Block a user