forked from React-Group/interstellar_ai
voice_backend comments
This commit is contained in:
parent
cdd4b80a43
commit
8a94beae31
1 changed files with 14 additions and 12 deletions
|
@ -1,24 +1,26 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
export const sendToVoiceRecognition = (audio_data: Blob): Promise<string> => {
|
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()
|
// Set the API URL dynamically based on the environment
|
||||||
formdata.append("audio", audio_data)
|
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/voice_recognition");
|
||||||
|
|
||||||
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/voice_recognition")
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
apiURL.hostname = window.location.hostname;
|
apiURL.hostname = window.location.hostname; // Use the current hostname in the browser
|
||||||
} else {
|
} 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)
|
return axios.post(apiURL.href, formdata)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
return response.data.response
|
return response.data.response; // Return the response from the API
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log("Error calling API:", error)
|
console.log("Error calling API:", error); // Log any error that occurs
|
||||||
postMessage({ status: 500 })
|
postMessage({ status: 500 }); // Indicate an error status to the worker
|
||||||
return "Error"
|
return "Error"; // Return a fallback error message
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
Loading…
Reference in a new issue