Spaces:
Configuration error
Configuration error
File size: 2,285 Bytes
610dd27 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
import { useCallback, useEffect, useState } from "react";
import Select from "react-select";
import { useLiveAPIContext } from "../../contexts/LiveAPIContext";
const voiceOptions = [
{ value: "Puck", label: "Puck" },
{ value: "Charon", label: "Charon" },
{ value: "Kore", label: "Kore" },
{ value: "Fenrir", label: "Fenrir" },
{ value: "Aoede", label: "Aoede" },
];
export default function VoiceSelector() {
const { config, setConfig } = useLiveAPIContext();
useEffect(() => {
const voiceName =
config.generationConfig?.speechConfig?.voiceConfig?.prebuiltVoiceConfig
?.voiceName || "Atari02";
const voiceOption = { value: voiceName, label: voiceName };
setSelectedOption(voiceOption);
}, [config]);
const [selectedOption, setSelectedOption] = useState<{
value: string;
label: string;
} | null>(voiceOptions[5]);
const updateConfig = useCallback(
(voiceName: string) => {
setConfig({
...config,
generationConfig: {
...config.generationConfig,
speechConfig: {
voiceConfig: {
prebuiltVoiceConfig: {
voiceName: voiceName,
},
},
},
},
});
},
[config, setConfig]
);
return (
<div className="select-group">
<label htmlFor="voice-selector">Voice</label>
<Select
id="voice-selector"
className="react-select"
classNamePrefix="react-select"
styles={{
control: (baseStyles) => ({
...baseStyles,
background: "var(--Neutral-15)",
color: "var(--Neutral-90)",
minHeight: "33px",
maxHeight: "33px",
border: 0,
}),
option: (styles, { isFocused, isSelected }) => ({
...styles,
backgroundColor: isFocused
? "var(--Neutral-30)"
: isSelected
? "var(--Neutral-20)"
: undefined,
}),
}}
value={selectedOption}
defaultValue={selectedOption}
options={voiceOptions}
onChange={(e) => {
setSelectedOption(e);
if (e) {
updateConfig(e.value);
}
}}
/>
</div>
);
}
|