Skip to content

Commit

Permalink
support playht3.0 languages
Browse files Browse the repository at this point in the history
  • Loading branch information
xquanluu committed Oct 16, 2024
1 parent 7aaea04 commit 8ea4a67
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ export const getSpeechSupportedLanguagesAndVoices = (
sid: string | undefined,
vendor: string,
label: string,
create_new: boolean = false,
) => {
const userData = parseJwt(getToken());
const apiUrl =
Expand All @@ -883,7 +884,7 @@ export const getSpeechSupportedLanguagesAndVoices = (
: `${API_SERVICE_PROVIDERS}/${sid}`) +
`/SpeechCredentials/speech/supportedLanguagesAndVoices?vendor=${vendor}${
label ? `&label=${label}` : ""
}`;
}${create_new ? "&create_new=true" : ""}`;
return getFetch<SpeechSupportedLanguagesAndVoices>(apiUrl);
};

Expand Down
30 changes: 28 additions & 2 deletions src/containers/internal/views/applications/speech-selection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
VENDOR_WELLSAID,
VENDOR_WHISPER,
VENDOR_SPEECHMATICS,
VENDOR_PLAYHT,
} from "src/vendor";
import {
LabelOptions,
Expand Down Expand Up @@ -199,6 +200,19 @@ export const SpeechProviderSelection = ({
if (synthesisGoogleCustomVoiceOptions.length > 0) {
updateTtsVoice(synthesisGoogleCustomVoiceOptions[0].value);
}
}
// PlayHT3.0 all voices are listed under english language, all voices can be used for multiple languages
else if (
synthVendor === VENDOR_PLAYHT &&
synthesisSupportedLanguagesAndVoices.tts.some(
(l) => l.value === "english",
)
) {
setSynthesisVoiceOptions(
synthesisSupportedLanguagesAndVoices.tts.find(
(tts) => tts.value === "english",
)!.voices,
);
} else {
setSynthesisVoiceOptions(voicesOpts);
}
Expand Down Expand Up @@ -262,6 +276,14 @@ export const SpeechProviderSelection = ({
updateTtsVoice(newLang!.voices[0].value);
return;
}
if (synthVendor === VENDOR_PLAYHT) {
const newLang = json.tts.find(
(lang) => lang.value === LANG_EN_US || lang.value === "english",
);
setSynthLang(newLang!.value);
updateTtsVoice(newLang!.voices[0].value);
return;
}
/** Google and AWS have different language lists */
/** If the new language doesn't map then default to "en-US" */
let newLang = json.tts.find((lang) => lang.value === synthLang);
Expand Down Expand Up @@ -412,7 +434,9 @@ export const SpeechProviderSelection = ({
id="synthesis_lang"
name="synthesis_lang"
value={synthLang}
options={synthesisLanguageOptions}
options={synthesisLanguageOptions.sort((a, b) =>
a.name.localeCompare(b.name),
)}
onChange={(e) => {
shouldUpdateTtsVoice.current = true;
const language = e.target.value;
Expand Down Expand Up @@ -467,7 +491,9 @@ export const SpeechProviderSelection = ({
id="synthesis_voice"
name="synthesis_voice"
value={synthVoice}
options={synthesisVoiceOptions}
options={synthesisVoiceOptions.sort((a, b) =>
a.name.localeCompare(b.name),
)}
onChange={(e) => setSynthVoice(e.target.value)}
/>
)}
Expand Down
1 change: 1 addition & 0 deletions src/containers/internal/views/speech-services/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => {
currentServiceProvider?.service_provider_sid,
vendor,
"",
credential ? false : true,
).then(({ json }) => {
if (json.models) {
setTtsModels(json.models);
Expand Down
1 change: 1 addition & 0 deletions src/vendor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export interface SynthesisVendors {
elevenlabs: VoiceLanguage[];
whisper: VoiceLanguage[];
deepgram: VoiceLanguage[];
playht: VoiceLanguage[];
}

export interface MSRawSpeech {
Expand Down

0 comments on commit 8ea4a67

Please sign in to comment.