Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support custom tts streaming #475

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ export interface SpeechCredential {
deepgram_tts_uri: null | string;
deepgram_stt_use_tls: number;
speechmatics_stt_uri: null | string;
use_audio_resampling: number;
use_base64_encoding: number;
tts_streaming_sample_rate: number;
use_tls: number;
}

export interface Alert {
Expand Down
99 changes: 98 additions & 1 deletion src/containers/internal/views/speech-services/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => {
AWS_CREDENTIAL_ACCESS_KEY,
);
const [roleArn, setRoleArn] = useState("");
const [useAudioResampling, setUseAudioResampling] = useState(false);
const [tmpUseAudioResampling, setTmpUseAudioResampling] = useState(false);
const [useBase64Encoding, setUseBase64Encoding] = useState(false);
const [tmpUseBase64Encoding, setTmpUseBase64Encoding] = useState(false);
const [useTls, setUseTls] = useState(false);
const [tmpUseTls, setTmpUseTls] = useState(false);
const [ttsStreamingSampleRate, setTtsStreamingSampleRate] = useState("8000");
const [tmpTtsStreamingSampleRate, setTmpTtsStreamingSampleRate] =
useState("8000");

const handleFile = (file: File) => {
const handleError = () => {
Expand Down Expand Up @@ -381,6 +390,10 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => {
custom_tts_url: customVendorTtsUrl || null,
custom_stt_url: customVendorSttUrl || null,
auth_token: customVendorAuthToken || null,
use_audio_resampling: useAudioResampling ? 1 : 0,
use_base64_encoding: useBase64Encoding ? 1 : 0,
use_tls: useTls ? 1 : 0,
tts_streaming_sample_rate: Number(ttsStreamingSampleRate || "8000"),
}),
...(vendor === VENDOR_NUANCE && {
client_id: clientId || null,
Expand Down Expand Up @@ -756,6 +769,26 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => {
);
setSpeechmaticsEndpoint(credential.data.speechmatics_stt_uri);
}
setUseAudioResampling(
(credential?.data?.use_audio_resampling || 0) > 0 ? true : false,
);
setTmpUseAudioResampling(
(credential?.data?.use_audio_resampling || 0) > 0 ? true : false,
);
setUseBase64Encoding(
(credential?.data?.use_base64_encoding || 0) > 0 ? true : false,
);
setTmpUseBase64Encoding(
(credential?.data?.use_base64_encoding || 0) > 0 ? true : false,
);
if (credential?.data?.tts_streaming_sample_rate) {
setTtsStreamingSampleRate(`${credential.data.tts_streaming_sample_rate}`);
setTmpTtsStreamingSampleRate(
`${credential.data.tts_streaming_sample_rate}`,
);
}
setUseTls((credential?.data?.use_tls || 0) > 0 ? true : false);
setTmpUseTls((credential?.data?.use_tls || 0) > 0 ? true : false);
}, [credential]);

const updateCustomVoices = (
Expand Down Expand Up @@ -914,14 +947,25 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => {
setTtsCheck(e.target.checked);
if (!e.target.checked) {
setTmpCustomVendorTtsUrl(customVendorTtsUrl);
setTmpUseAudioResampling(useAudioResampling);
setTmpUseTls(useTls);
setTmpUseBase64Encoding(useBase64Encoding);
setCustomVendorTtsUrl("");
setUseAudioResampling(false);
setUseTls(false);
setUseBase64Encoding(false);
setTmpTtsStreamingSampleRate(ttsStreamingSampleRate);
} else {
setCustomVendorTtsUrl(tmpCustomVendorTtsUrl);
setUseAudioResampling(tmpUseAudioResampling);
setUseTls(tmpUseTls);
setUseBase64Encoding(tmpUseBase64Encoding);
setTtsStreamingSampleRate(tmpTtsStreamingSampleRate);
}
}}
>
<label htmlFor="custom_vendor_use_for_tts">
TTS HTTP URL<span>*</span>
TTS URL<span>*</span>
</label>
<input
id="custom_vendor_use_for_tts"
Expand All @@ -934,6 +978,59 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => {
setCustomVendorTtsUrl(e.target.value);
}}
/>
<label htmlFor="use_audio_resampling" className="chk">
<input
id="use_audio_resampling"
name="use_audio_resampling"
type="checkbox"
onChange={(e) => setUseAudioResampling(e.target.checked)}
defaultChecked={useAudioResampling}
/>
<div>Tts streaming use audio resampling</div>
</label>

{useAudioResampling && (
<>
{" "}
<label htmlFor="custom_vendor_tts_streaming_sample_rate">
Tts streaming audio sample rate
{useAudioResampling ? <span>*</span> : ""}
</label>
<input
id="custom_vendor_tts_streaming_sample_rate"
type="number"
name="custom_vendor_tts_streaming_sample_rate"
required={useAudioResampling}
value={ttsStreamingSampleRate}
disabled={!useAudioResampling}
onChange={(e) => {
setTtsStreamingSampleRate(e.target.value);
}}
/>
</>
)}

<label htmlFor="use_base64_encoding" className="chk">
<input
id="use_base64_encoding"
name="use_base64_encoding"
type="checkbox"
onChange={(e) => setUseBase64Encoding(e.target.checked)}
defaultChecked={useBase64Encoding}
/>
<div>Tts streaming use base64 encoding</div>
</label>

<label htmlFor="use_tls" className="chk">
<input
id="use_tls"
name="use_tls"
type="checkbox"
onChange={(e) => setUseTls(e.target.checked)}
defaultChecked={useTls}
/>
<div>Tts streaming use TLS</div>
</label>
</Checkzone>

<Checkzone
Expand Down
Loading