Merge remote-tracking branch 'github/master'
This commit is contained in:
@@ -266,8 +266,6 @@ export default (props: {
|
|||||||
const [totalCost, setTotalCost] = useState(getTotalCost());
|
const [totalCost, setTotalCost] = useState(getTotalCost());
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const { langCode, setLangCode } = useContext(langCodeContext);
|
const { langCode, setLangCode } = useContext(langCodeContext);
|
||||||
// type is MediaDeviceInfo
|
|
||||||
const [devices, setDevices] = useState([] as MediaDeviceInfo[]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleKeyPress = (event: any) => {
|
const handleKeyPress = (event: any) => {
|
||||||
|
|||||||
11
src/tts.tsx
11
src/tts.tsx
@@ -1,3 +1,4 @@
|
|||||||
|
import { useState } from "preact/hooks";
|
||||||
import { ChatStore, addTotalCost } from "./app";
|
import { ChatStore, addTotalCost } from "./app";
|
||||||
|
|
||||||
interface TTSProps {
|
interface TTSProps {
|
||||||
@@ -6,6 +7,7 @@ interface TTSProps {
|
|||||||
text: string;
|
text: string;
|
||||||
}
|
}
|
||||||
export default function TTSButton(props: TTSProps) {
|
export default function TTSButton(props: TTSProps) {
|
||||||
|
const [generating, setGenerating] = useState(false);
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -13,7 +15,7 @@ export default function TTSButton(props: TTSProps) {
|
|||||||
const api_key = props.chatStore.tts_key;
|
const api_key = props.chatStore.tts_key;
|
||||||
const model = "tts-1";
|
const model = "tts-1";
|
||||||
const input = props.text;
|
const input = props.text;
|
||||||
const voice = "alloy";
|
const voice = props.chatStore.tts_voice;
|
||||||
|
|
||||||
const body: Record<string, any> = {
|
const body: Record<string, any> = {
|
||||||
model,
|
model,
|
||||||
@@ -25,6 +27,8 @@ export default function TTSButton(props: TTSProps) {
|
|||||||
body["speed"] = props.chatStore.tts_speed;
|
body["speed"] = props.chatStore.tts_speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setGenerating(true);
|
||||||
|
|
||||||
fetch(api, {
|
fetch(api, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -44,10 +48,13 @@ export default function TTSButton(props: TTSProps) {
|
|||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
const audio = new Audio(url);
|
const audio = new Audio(url);
|
||||||
audio.play();
|
audio.play();
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
setGenerating(false);
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
🔈
|
{generating ? "🤔" : "🔈"}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user