# Playing audion with client side js

**URL:** <https://forum.robusta.ai/t/playing-audion-with-client-side-js/650>\
**Category:** Applications\
**Tags:** applications, javascript\
**Created:** [December 9, 2024, 9:06am UTC](https://forum.robusta.ai/t/playing-audion-with-client-side-js/650 "2024-12-09T09:06:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![serkanulucan79](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@serkanulucan79](https://forum.robusta.ai/u/serkanulucan79)\
**Post date:** [December 9, 2024, 9:06am UTC](https://forum.robusta.ai/t/playing-audion-with-client-side-js/650/1 "2024-12-09T09:06:15Z")

</div>

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();

---

<div class="post-metadata">

**Author:** ![Yasin.Baykan](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robusta.ai/yasin.baykan/32/86_2.png) [@Yasin.Baykan](https://forum.robusta.ai/u/Yasin.Baykan)\
**Post date:** [December 9, 2024, 10:04am UTC](https://forum.robusta.ai/t/playing-audion-with-client-side-js/650/2 "2024-12-09T10:04:47Z")

</div>

for further investigation please submit a request from our portal.  
[https://robusta-ca.atlassian.net/servicedesk/customer/portals](https://robusta-ca.atlassian.net/servicedesk/customer/portals)

---

<div class="post-metadata">

**Author:** ![serkanulucan79](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@serkanulucan79](https://forum.robusta.ai/u/serkanulucan79)\
**Post date:** [December 9, 2024, 10:26am UTC](https://forum.robusta.ai/t/playing-audion-with-client-side-js/650/3 "2024-12-09T10:26:30Z")

</div>

sorry, I have no access to service desk.
