try fetch whsiper API
This commit is contained in:
@@ -571,30 +571,36 @@ export default function ChatBOX(props: {
|
|||||||
});
|
});
|
||||||
|
|
||||||
reader.onloadend = async () => {
|
reader.onloadend = async () => {
|
||||||
const base64data = reader.result;
|
try {
|
||||||
|
const base64data = reader.result;
|
||||||
|
|
||||||
// post to openai whisper api
|
// post to openai whisper api
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
// append file
|
// append file
|
||||||
formData.append("file", blob, "audio.ogx");
|
formData.append("file", blob, "audio.ogx");
|
||||||
formData.append("model", "whisper-1");
|
formData.append("model", "whisper-1");
|
||||||
formData.append("response_format", "text");
|
formData.append("response_format", "text");
|
||||||
formData.append("prompt", prompt);
|
formData.append("prompt", prompt);
|
||||||
|
|
||||||
const response = await fetch(chatStore.whisper_api, {
|
const response = await fetch(chatStore.whisper_api, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${
|
Authorization: `Bearer ${
|
||||||
chatStore.whisper_api || chatStore.apiKey
|
chatStore.whisper_api || chatStore.apiKey
|
||||||
}`,
|
}`,
|
||||||
},
|
},
|
||||||
body: formData,
|
body: formData,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { text } = await response.json();
|
const { text } = await response.json();
|
||||||
|
|
||||||
setInputMsg(inputMsg ? inputMsg + " " + text : text);
|
setInputMsg(inputMsg ? inputMsg + " " + text : text);
|
||||||
setIsRecording("Mic");
|
} catch (error) {
|
||||||
|
alert(error);
|
||||||
|
console.log(error);
|
||||||
|
} finally {
|
||||||
|
setIsRecording("Mic");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user