support tts format

This commit is contained in:
2023-11-30 12:01:15 +08:00
parent 97a75ce35f
commit 92252f66ed
3 changed files with 22 additions and 1 deletions

View File

@@ -59,6 +59,7 @@ export interface ChatStore {
tts_voice: string;
tts_speed: number;
tts_speed_enabled: boolean;
tts_format: string;
image_gen_api: string;
image_gen_key: string;
json_mode: boolean;
@@ -79,6 +80,7 @@ export const newChatStore = (
tts_key = "",
tts_speed = 1.0,
tts_speed_enabled = false,
tts_format = "mp3",
toolsString = "",
image_gen_api = "https://api.openai.com/v1/images/generations",
image_gen_key = "",
@@ -118,6 +120,7 @@ export const newChatStore = (
image_gen_api: image_gen_api,
image_gen_key: image_gen_key,
json_mode: json_mode,
tts_format: tts_format,
};
};
@@ -275,6 +278,7 @@ export function App() {
chatStore.tts_key,
chatStore.tts_speed,
chatStore.tts_speed_enabled,
chatStore.tts_format,
chatStore.toolsString,
chatStore.image_gen_api,
chatStore.image_gen_key,

View File

@@ -22,6 +22,7 @@ const TTS_VOICES: string[] = [
"nova",
"shimmer",
];
const TTS_FORMAT: string[] = ["mp3", "opus", "aac", "flac"];
const Help = (props: { children: any; help: string }) => {
return (
@@ -510,6 +511,22 @@ export default (props: {
help={"TTS Speed"}
{...props}
/>
<Help help="tts response format">
<label className="m-2 p-2">TTS Format</label>
<select
className="m-2 p-2"
value={props.chatStore.tts_format}
onChange={(event: any) => {
const format = event.target.value as string;
props.chatStore.tts_format = format;
props.setChatStore({ ...props.chatStore });
}}
>
{TTS_FORMAT.map((opt) => (
<option value={opt}>{opt}</option>
))}
</select>
</Help>
<Input
field="image_gen_key"
help="image generation service api key"

View File

@@ -29,7 +29,7 @@ export default function TTSButton(props: TTSProps) {
model,
input,
voice,
response_format: "opus",
response_format: props.chatStore.tts_format || "mp3",
};
if (props.chatStore.tts_speed_enabled) {
body["speed"] = props.chatStore.tts_speed;