interstellar_ai/app/backend/voice_backend.ts

24 lines
714 B
TypeScript
Raw Normal View History

2024-09-25 12:33:52 +02:00
import axios from "axios";
2024-09-30 12:45:19 +02:00
export const sendToVoiceRecognition = (audio_data: Blob): Promise<string> => {
2024-09-26 09:37:33 +02:00
2024-09-30 12:45:19 +02:00
const formdata = new FormData()
formdata.append("audio", audio_data)
2024-09-26 09:46:32 +02:00
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/voice_recognition")
2024-10-07 11:16:51 +02:00
if (typeof window !== 'undefined') {
apiURL.hostname = window.location.hostname;
} else {
apiURL.hostname = "localhost"
}
return axios.post(apiURL.href, formdata)
2024-09-30 12:45:19 +02:00
.then((response) => {
return response.data.response
})
.catch(error => {
console.log("Error calling API:", error)
postMessage({ status: 500 })
return "Error"
})
}