AI4Bharat / Indic-TTS

Text-to-Speech for languages of India
MIT License
130 stars 29 forks source link

base64 embed into audio element #5

Open mohit4bug opened 1 year ago

mohit4bug commented 1 year ago

Inside index.html in (front_end/index.html)

You are using this code:


 let arrayString = 'data:audio/wav;base64,' + response["audio"][0]["audioContent"]
                        console.log(arrayString)
                        // let arrayBuffer = atob(arrayString)
                        // console.log(arrayBuffer)
                        // const blob = new Blob([arrayBuffer], { type: "audio/wav; codecs=MS_PCM" });
                        // const url = window.URL.createObjectURL(blob);
                        audioElement = document.getElementById("audio-output")
                        audioElement.src = arrayString;
                        audioElement.style.display = 'block'```

Why do you directly adding arrayString into src of audioElement, and i tried the same in vanilla JS is does not work for me.
`generateButton.addEventListener("click", async () => {
const source = sourceRef.value
const base64 = await fetchAudio(source)
// console.log(base64)
let arrayString = "data:audio/wav;base64," + base64
audioElement.src = arrayString

    // let arrayBuffer = atob(arrayString)
    // console.log(arrayBuffer + "This is buffer")
    // const blob = new Blob([arrayBuffer], { type: "audio/wav; codecs=MS_PCM" });
    // const url = window.URL.createObjectURL(blob)
    // audioElement.src = url

})
`