interstellar_ai/app/backend/voice_backend.ts
2024-10-07 11:16:51 +02:00

24 lines
No EOL
714 B
TypeScript

import axios from "axios";
export const sendToVoiceRecognition = (audio_data: Blob): Promise<string> => {
const formdata = new FormData()
formdata.append("audio", audio_data)
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/voice_recognition")
if (typeof window !== 'undefined') {
apiURL.hostname = window.location.hostname;
} else {
apiURL.hostname = "localhost"
}
return axios.post(apiURL.href, formdata)
.then((response) => {
return response.data.response
})
.catch(error => {
console.log("Error calling API:", error)
postMessage({ status: 500 })
return "Error"
})
}