Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "code": 401,
- "error": "Unauthorized"
- }
- $(function () {
- $("#btnPOst").click(function () {
- var username= "XXXX-XXXX-XXXX";
- var password = "XXXX-XXXX-XXXX";
- var request = $("#text-to-speech input[name=speech-text]").val();
- var url = "https://stream.watsonplatform.net/text-to-speech/api/v1/synthesize?voice=en-US_MichaelVoice&accept=audio/wav&text=" + request;
- $.ajax({
- type: "POST",
- url: url,
- dataType: "application/json; charset=utf-8",
- headers: {
- 'Content-Type': 'application/json',
- 'Accept': 'audio/wav',
- 'Authorization': ("Basic " + btoa(username + ":" + password))
- },
- success: function (content) {
- alert('ok');
- },
- });
- $("#speech").attr("src", url)[0].play();
- });
- });
- <input type="text" name="speech-text" TextMode="MultiLine" />
- <input type="button" id="btnPOst" value="Play" />
- <audio id="speech" autoplay preload="auto" autobuffer controls class="audio"></audio>
Add Comment
Please, Sign In to add comment