Skip to content

Commit

Permalink
fix(tts): get tts engine name from the endpoint
Browse files Browse the repository at this point in the history
Use the engine's name as reported by `/ws/tts-engines` in the engines and voices screens of the settings dialog.

#228
  • Loading branch information
marisademeglio committed Jun 28, 2024
1 parent a588f77 commit d1475f4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
49 changes: 25 additions & 24 deletions src/renderer/components/TtsEnginesConfig/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ const enginePropertyKeys = [
'org.daisy.pipeline.tts.azure.region',
'org.daisy.pipeline.tts.google.apikey',
]
const engineIds = [
'org.daisy.pipeline.tts.azure',
'org.daisy.pipeline.tts.google',
]

const engineNames = {
'org.daisy.pipeline.tts.azure': 'Azure',
'org.daisy.pipeline.tts.google': 'Google',
Expand Down Expand Up @@ -148,22 +153,24 @@ export function TtsEnginesConfigPane({
they will be available under 'Voices'.
</p>
<ul>
{Object.keys(engineNames).map((engineKeyPrefix, idx) => (
<li key={engineKeyPrefix + '-' + idx}>
{engineNames[engineKeyPrefix]}
{/* {Object.keys(engineNames).map((engineKeyPrefix, idx) => ( */}
{engineIds.map((engineId, idx) => (
<li key={engineId + '-' + idx}>
{pipeline.ttsEnginesStates[
engineId.split('.').reverse()[0]
]?.name ?? engineId}

<ul>
{enginePropertyKeys
.filter((propkey) =>
propkey.includes(engineKeyPrefix)
)
.filter((propkey) => propkey.includes(engineId))
.map((propkey, idx) => (
<li key={propkey + '-' + idx}>
<label htmlFor={propkey}>
{(() => {
// the propkey looks like org.daisy.pipeline.tts.enginename.propkeyname
// label the form field as "Propkeyname"
let propkey_ = propkey.replace(
engineKeyPrefix + '.',
engineId + '.',
''
)
return (
Expand All @@ -188,23 +195,21 @@ export function TtsEnginesConfigPane({
/>
</li>
))}
{engineMessage[engineKeyPrefix] && (
{engineMessage[engineId] && (
<li className="error">
{engineMessage[engineKeyPrefix].split('\n')
{engineMessage[engineId].split('\n')
.length === 1 ? (
<span>
{engineMessage[engineKeyPrefix]}
</span>
<span>{engineMessage[engineId]}</span>
) : (
<details>
<summary>
{
engineMessage[
engineKeyPrefix
engineId
].split('\n')[0]
}
</summary>
{engineMessage[engineKeyPrefix]
{engineMessage[engineId]
.split('\n')
.slice(1)
.join('\n')}
Expand All @@ -213,29 +218,25 @@ export function TtsEnginesConfigPane({
</li>
)}
{['azure', 'google'].includes(
engineKeyPrefix.split('.').slice(-1)[0]
engineId.split('.').slice(-1)[0]
) && (
<li>
{!isConnectedToTTSEngine(engineKeyPrefix) ||
enginePropsChanged[engineKeyPrefix] ? (
{!isConnectedToTTSEngine(engineId) ||
enginePropsChanged[engineId] ? (
<button
onClick={(e) => {
e.preventDefault()
connectToTTSEngine(
engineKeyPrefix
)
connectToTTSEngine(engineId)
}}
>
Connect
</button>
) : isConnectedToTTSEngine(
engineKeyPrefix
) ? (
) : isConnectedToTTSEngine(engineId) ? (
<button
onClick={(e) => {
e.preventDefault()
disconnectFromTTSEngine(
engineKeyPrefix
engineId
)
}}
>
Expand Down
10 changes: 9 additions & 1 deletion src/renderer/components/TtsVoicesConfig/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export function TtsVoicesConfigPane({
onChangePreferredVoices,
onChangeDefaultVoices,
}) {
const { pipeline } = useWindowStore()

const [preferredVoices, setPreferredVoices] = useState([
...userPreferredVoices,
])
Expand Down Expand Up @@ -418,7 +420,13 @@ export function TtsVoicesConfigPane({
{voicesTransliterations[v.name] ??
v.name}
</td>
<td>{v.engine}</td>
<td>
{
pipeline.ttsEnginesStates[
v.engine
].name
}
</td>
<td>{languageNames.of(v.lang)}</td>
<td>{v.gender}</td>
<td className="actions">
Expand Down
6 changes: 6 additions & 0 deletions src/shared/parser/pipelineXmlConverter/ttsEnginesToJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ function ttsEnginesToJson(
if (ttsEngineElem.getAttribute('message').length > 0) {
acc[key].message = ttsEngineElem.getAttribute('message')
}
if (ttsEngineElem.getAttribute('voices').length > 0) {
acc[key].voicesUrl = ttsEngineElem.getAttribute('voices')
}
if (ttsEngineElem.getAttribute('nicename').length > 0) {
acc[key].name = ttsEngineElem.getAttribute('nicename')
}
}
return acc
}, {})
Expand Down
2 changes: 2 additions & 0 deletions src/shared/types/ttsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ export type TtsEngineState = {
status?: 'disabled' | 'connecting' | 'available' | 'disconnecting' | 'error'
features?: Array<string>
message?: string
name?: string
voicesUrl?: string
}

0 comments on commit d1475f4

Please sign in to comment.