mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 10:46:35 +00:00
Use language picker for cloud tts language (#16363)
* Use language picker for cloud tts language * Update ha-browse-media-tts.ts
This commit is contained in:
parent
3ed3dab0a1
commit
f2a8528429
@ -21,6 +21,7 @@ import { buttonLinkStyle } from "../../resources/styles";
|
|||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import "../ha-select";
|
import "../ha-select";
|
||||||
import "../ha-textarea";
|
import "../ha-textarea";
|
||||||
|
import "../ha-language-picker";
|
||||||
|
|
||||||
export interface TtsMediaPickedEvent {
|
export interface TtsMediaPickedEvent {
|
||||||
item: MediaPlayerItem;
|
item: MediaPlayerItem;
|
||||||
@ -103,21 +104,17 @@ class BrowseMediaTTS extends LitElement {
|
|||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div class="cloud-options">
|
<div class="cloud-options">
|
||||||
<ha-select
|
<ha-language-picker
|
||||||
fixedMenuPosition
|
.hass=${this.hass}
|
||||||
naturalMenuWidth
|
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.components.media-browser.tts.language"
|
"ui.components.media-browser.tts.language"
|
||||||
)}
|
)}
|
||||||
.value=${selectedVoice[0]}
|
.value=${selectedVoice[0]}
|
||||||
@selected=${this._handleLanguageChange}
|
.languages=${languages}
|
||||||
@closed=${stopPropagation}
|
@closed=${stopPropagation}
|
||||||
|
@value-changed=${this._handleLanguageChange}
|
||||||
>
|
>
|
||||||
${languages.map(
|
</ha-language-picker>
|
||||||
([key, label]) =>
|
|
||||||
html`<mwc-list-item .value=${key}>${label}</mwc-list-item>`
|
|
||||||
)}
|
|
||||||
</ha-select>
|
|
||||||
|
|
||||||
<ha-select
|
<ha-select
|
||||||
fixedMenuPosition
|
fixedMenuPosition
|
||||||
@ -184,10 +181,10 @@ class BrowseMediaTTS extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _handleLanguageChange(ev) {
|
async _handleLanguageChange(ev) {
|
||||||
if (ev.target.value === this._cloudOptions![0]) {
|
if (ev.detail.value === this._cloudOptions![0]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._cloudOptions = [ev.target.value, this._cloudOptions![1]];
|
this._cloudOptions = [ev.detail.value, this._cloudOptions![1]];
|
||||||
}
|
}
|
||||||
|
|
||||||
async _handleGenderChange(ev) {
|
async _handleGenderChange(ev) {
|
||||||
@ -256,7 +253,8 @@ class BrowseMediaTTS extends LitElement {
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
}
|
}
|
||||||
.cloud-options ha-select {
|
.cloud-options ha-select,
|
||||||
|
ha-language-picker {
|
||||||
width: 48%;
|
width: 48%;
|
||||||
}
|
}
|
||||||
ha-textarea {
|
ha-textarea {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { caseInsensitiveStringCompare } from "../../common/string/compare";
|
import { caseInsensitiveStringCompare } from "../../common/string/compare";
|
||||||
import { LocalizeFunc } from "../../common/translations/localize";
|
import { LocalizeFunc } from "../../common/translations/localize";
|
||||||
import { translationMetadata } from "../../resources/translations-metadata";
|
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
|
|
||||||
export interface CloudTTSInfo {
|
export interface CloudTTSInfo {
|
||||||
@ -11,7 +10,7 @@ export const getCloudTTSInfo = (hass: HomeAssistant) =>
|
|||||||
hass.callWS<CloudTTSInfo>({ type: "cloud/tts/info" });
|
hass.callWS<CloudTTSInfo>({ type: "cloud/tts/info" });
|
||||||
|
|
||||||
export const getCloudTtsLanguages = (info?: CloudTTSInfo) => {
|
export const getCloudTtsLanguages = (info?: CloudTTSInfo) => {
|
||||||
const languages: Array<[string, string]> = [];
|
const languages: string[] = [];
|
||||||
|
|
||||||
if (!info) {
|
if (!info) {
|
||||||
return languages;
|
return languages;
|
||||||
@ -23,25 +22,9 @@ export const getCloudTtsLanguages = (info?: CloudTTSInfo) => {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
seen.add(lang);
|
seen.add(lang);
|
||||||
|
languages.push(lang);
|
||||||
let label = lang;
|
|
||||||
|
|
||||||
if (lang in translationMetadata.translations) {
|
|
||||||
label = translationMetadata.translations[lang].nativeName;
|
|
||||||
} else {
|
|
||||||
const [langFamily, dialect] = lang.split("-");
|
|
||||||
if (langFamily in translationMetadata.translations) {
|
|
||||||
label = `${translationMetadata.translations[langFamily].nativeName}`;
|
|
||||||
|
|
||||||
if (langFamily.toLowerCase() !== dialect.toLowerCase()) {
|
|
||||||
label += ` (${dialect})`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
languages.push([lang, label]);
|
|
||||||
}
|
}
|
||||||
return languages.sort((a, b) => caseInsensitiveStringCompare(a[1], b[1]));
|
return languages;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getCloudTtsSupportedGenders = (
|
export const getCloudTtsSupportedGenders = (
|
||||||
|
@ -8,6 +8,7 @@ import "../../../../components/ha-card";
|
|||||||
import "../../../../components/ha-select";
|
import "../../../../components/ha-select";
|
||||||
import "../../../../components/ha-svg-icon";
|
import "../../../../components/ha-svg-icon";
|
||||||
import "../../../../components/ha-switch";
|
import "../../../../components/ha-switch";
|
||||||
|
import "../../../../components/ha-language-picker";
|
||||||
import { CloudStatusLoggedIn, updateCloudPref } from "../../../../data/cloud";
|
import { CloudStatusLoggedIn, updateCloudPref } from "../../../../data/cloud";
|
||||||
import {
|
import {
|
||||||
CloudTTSInfo,
|
CloudTTSInfo,
|
||||||
@ -54,34 +55,33 @@ export class CloudTTSPref extends LitElement {
|
|||||||
'"tts.cloud_say"'
|
'"tts.cloud_say"'
|
||||||
)}
|
)}
|
||||||
<br /><br />
|
<br /><br />
|
||||||
|
<div class="row">
|
||||||
|
<ha-language-picker
|
||||||
|
.hass=${this.hass}
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.cloud.account.tts.default_language"
|
||||||
|
)}
|
||||||
|
.disabled=${this.savingPreferences}
|
||||||
|
.value=${defaultVoice[0]}
|
||||||
|
.languages=${languages}
|
||||||
|
@value-changed=${this._handleLanguageChange}
|
||||||
|
>
|
||||||
|
</ha-language-picker>
|
||||||
|
|
||||||
<ha-select
|
<ha-select
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.cloud.account.tts.default_language"
|
"ui.panel.config.cloud.account.tts.default_gender"
|
||||||
)}
|
)}
|
||||||
.disabled=${this.savingPreferences}
|
.disabled=${this.savingPreferences}
|
||||||
.value=${defaultVoice[0]}
|
.value=${defaultVoice[1]}
|
||||||
@selected=${this._handleLanguageChange}
|
@selected=${this._handleGenderChange}
|
||||||
>
|
>
|
||||||
${languages.map(
|
${genders.map(
|
||||||
([key, label]) =>
|
([key, label]) =>
|
||||||
html`<mwc-list-item .value=${key}>${label}</mwc-list-item>`
|
html`<mwc-list-item .value=${key}>${label}</mwc-list-item>`
|
||||||
)}
|
)}
|
||||||
</ha-select>
|
</ha-select>
|
||||||
|
</div>
|
||||||
<ha-select
|
|
||||||
.label=${this.hass.localize(
|
|
||||||
"ui.panel.config.cloud.account.tts.default_gender"
|
|
||||||
)}
|
|
||||||
.disabled=${this.savingPreferences}
|
|
||||||
.value=${defaultVoice[1]}
|
|
||||||
@selected=${this._handleGenderChange}
|
|
||||||
>
|
|
||||||
${genders.map(
|
|
||||||
([key, label]) =>
|
|
||||||
html`<mwc-list-item .value=${key}>${label}</mwc-list-item>`
|
|
||||||
)}
|
|
||||||
</ha-select>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="card-actions">
|
<div class="card-actions">
|
||||||
<mwc-button @click=${this._openTryDialog}>
|
<mwc-button @click=${this._openTryDialog}>
|
||||||
@ -115,11 +115,11 @@ export class CloudTTSPref extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _handleLanguageChange(ev) {
|
async _handleLanguageChange(ev) {
|
||||||
if (ev.target.value === this.cloudStatus!.prefs.tts_default_voice[0]) {
|
if (ev.detail.value === this.cloudStatus!.prefs.tts_default_voice[0]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.savingPreferences = true;
|
this.savingPreferences = true;
|
||||||
const language = ev.target.value;
|
const language = ev.detail.value;
|
||||||
|
|
||||||
const curGender = this.cloudStatus!.prefs.tts_default_voice[1];
|
const curGender = this.cloudStatus!.prefs.tts_default_voice[1];
|
||||||
const genders = this.getSupportedGenders(
|
const genders = this.getSupportedGenders(
|
||||||
@ -185,6 +185,18 @@ export class CloudTTSPref extends LitElement {
|
|||||||
right: auto;
|
right: auto;
|
||||||
left: 24px;
|
left: 24px;
|
||||||
}
|
}
|
||||||
|
.row {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
.row > * {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
.row > *:first-child {
|
||||||
|
margin-right: 8px;
|
||||||
|
}
|
||||||
|
.row > *:last-child {
|
||||||
|
margin-left: 8px;
|
||||||
|
}
|
||||||
.card-actions {
|
.card-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row-reverse;
|
flex-direction: row-reverse;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user