main #138

Merged
Patrick_Pluto merged 36 commits from sageTheDm/interstellar_ai:main into main 2024-10-11 10:19:08 +02:00
Showing only changes of commit 8a94beae31 - Show all commits

View file

@ -1,24 +1,26 @@
import axios from "axios";
export const sendToVoiceRecognition = (audio_data: Blob): Promise<string> => {
// Create a new FormData instance to send the audio file
const formdata = new FormData();
formdata.append("audio", audio_data); // Append the audio data to the FormData
const formdata = new FormData()
formdata.append("audio", audio_data)
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/voice_recognition")
// Set the API URL dynamically based on the environment
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/voice_recognition");
if (typeof window !== 'undefined') {
apiURL.hostname = window.location.hostname;
apiURL.hostname = window.location.hostname; // Use the current hostname in the browser
} else {
apiURL.hostname = "localhost"
apiURL.hostname = "localhost"; // Fallback for server-side
}
// Send the audio data to the API using POST request
return axios.post(apiURL.href, formdata)
.then((response) => {
return response.data.response
return response.data.response; // Return the response from the API
})
.catch(error => {
console.log("Error calling API:", error)
postMessage({ status: 500 })
return "Error"
})
}
console.log("Error calling API:", error); // Log any error that occurs
postMessage({ status: 500 }); // Indicate an error status to the worker
return "Error"; // Return a fallback error message
});
};