C
C#3y ago
Gage

Working with URL Audio [Answered]

How would one use this URL to render audio inside the On get method of a razor page? https://api.streamelements.com/kappa/v2/speech?voice=Brian&text= The link provided works by appending a string to the end of the URL and then generating a TTS audio file. I would like to play that audio file on the users end once they load that specific razor page (hence the onGet method)
30 Replies
Angius
Angius3y ago
Javascript
Gage
GageOP3y ago
so this actually came from JS originally. https://github.com/5E7EN/TTS-Emulator/blob/master/index.html And idea how I would convert the JS in this to onload rather than onClick by reading the text area?
GitHub
TTS-Emulator/index.html at master · 5E7EN/TTS-Emulator
Online emulator for the Brian TTS voice by StreamElements - TTS-Emulator/index.html at master · 5E7EN/TTS-Emulator
Angius
Angius3y ago
Just run the code directly
Gage
GageOP3y ago
The problem here is not that I don't know what needs done, its that I dont know JS
Angius
Angius3y ago
element.onclick = function () {
console.log('hello');
}
element.onclick = function () {
console.log('hello');
}
would just turn into
console.log('hello');
console.log('hello');
Simple as that
Gage
GageOP3y ago
how would I convert this
document.getElementById('button').onclick = async function () {
let text = document.getElementById(p).value;
let speak = await fetch('https://api.streamelements.com/kappa/v2/speech?voice=Brian&text=' + encodeURIComponent(text.trim()));
if (speak.status !== 200) {
alert(await speak.text());
return;
}
let mp3 = await speak.blob();
let blobUrl = URL.createObjectURL(mp3);
document.getElementById('source').setAttribute('src', blobUrl);
let audio = document.getElementById('audio');
audio.pause();
audio.load();
audio.play();
};
document.getElementById('button').onclick = async function () {
let text = document.getElementById(p).value;
let speak = await fetch('https://api.streamelements.com/kappa/v2/speech?voice=Brian&text=' + encodeURIComponent(text.trim()));
if (speak.status !== 200) {
alert(await speak.text());
return;
}
let mp3 = await speak.blob();
let blobUrl = URL.createObjectURL(mp3);
document.getElementById('source').setAttribute('src', blobUrl);
let audio = document.getElementById('audio');
audio.pause();
audio.load();
audio.play();
};
Angius
Angius3y ago
I just told you how
Gage
GageOP3y ago
not really
Angius
Angius3y ago
Or, well, seeing how the code in that repo is async, you might need
(async () => {
console.log('hello');
})();
(async () => {
console.log('hello');
})();
Yes really
Angius
Angius3y ago
Gage
GageOP3y ago
(async () => {
let speak = await fetch('https://api.streamelements.com/kappa/v2/speech?voice=Brian&text=' + encodeURIComponent(text.trim()));

if (speak.status !== 200) {
alert(await speak.text());
return;
}

let mp3 = await speak.blob();
let blobUrl = URL.createObjectURL(mp3);
})();
(async () => {
let speak = await fetch('https://api.streamelements.com/kappa/v2/speech?voice=Brian&text=' + encodeURIComponent(text.trim()));

if (speak.status !== 200) {
alert(await speak.text());
return;
}

let mp3 = await speak.blob();
let blobUrl = URL.createObjectURL(mp3);
})();
what needs to happen with that ^
Angius
Angius3y ago
Just place it in a js file and load it on the page
Gage
GageOP3y ago
you didn't tell me about passing variables into it or accessing it on a page by page basis
Angius
Angius3y ago
Or place it between <script> tags That original function doesn't take any variables
Gage
GageOP3y ago
yeah it does, it takes the text area's string as a variable that parameter then converts into a mp3
Angius
Angius3y ago
It literally doesn't take any variables
Gage
GageOP3y ago
what are you saying
Angius
Angius3y ago
List of arguments is empty
Angius
Angius3y ago
Gage
GageOP3y ago
I just told you I don't know java script
Angius
Angius3y ago
You're gonna have a hard time, then
Gage
GageOP3y ago
so then show me that's why I posted in help lmfao
Angius
Angius3y ago
This server isn't for spoonfeeding
Gage
GageOP3y ago
jesus christ
Angius
Angius3y ago
I can help you, I won't give you a solution straight
Gage
GageOP3y ago
telling me how to pass parameters is not spoon feeding just leave at this point
Angius
Angius3y ago
It works exactly as in C#
Gage
GageOP3y ago
fuck you
Accord
Accord3y ago
✅ This post has been marked as answered!
Angius
Angius3y ago
function foo(x) {
console.log(`Your number is ${x}`);
}

foo(43);
function foo(x) {
console.log(`Your number is ${x}`);
}

foo(43);
Want results from more Discord servers?
Add your server