Hi. I use an text2speech api. I have been trying to play sound through chrome browser. To do this I run a client site JS as follow. When I run this code on chrome developer console, it’s ok. But when using the run script activity under applications, the js runs without any exception, but I can’t hear the sound. Is there any recommendation to try.
Here is js. But not that I didnt give the correct api key since it belongs to my account.
function textToSpeech() {
// Prepare request body
var requestData = {
“text”: “çok güzel”,
“model_id”: “eleven_turbo_v2_5”,
“language_id”: “tr”
};
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://api.elevenlabs.io/v1/text-to-speech/21m00Tcm4TlvDq8ikWAM/with-timestamps", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("xi-api-key", "thisincorrectkey967565");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) { // Request finished
if (xhr.status >= 200 && xhr.status < 300) {
var result = JSON.parse(xhr.responseText); // Parse the JSON response
// Check if audio_base64 exists
if (result.audio_base64) {
var audioSrc = "data:audio/wav;base64," + result.audio_base64;
var audio = new Audio(audioSrc); // Create an Audio object
audio.play(); // Play the audio
} else {
console.error('audio_base64 key not found in the response');
}
} else {
console.error('HTTP error! Status:', xhr.status);
}
}
};
// Send the request with JSON data
xhr.send(JSON.stringify(requestData));
}
// Call the function
textToSpeech();