C
C#2y 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
Angius2y ago
Javascript
Gage
Gage2y 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
Angius2y ago
Just run the code directly
Gage
Gage2y ago
The problem here is not that I don't know what needs done, its that I dont know JS
Angius
Angius2y 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
Gage2y 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
Angius2y ago
I just told you how
Gage
Gage2y ago
not really
Angius
Angius2y 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
Angius2y ago
Gage
Gage2y 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
Angius2y ago
Just place it in a js file and load it on the page
Gage
Gage2y ago
you didn't tell me about passing variables into it or accessing it on a page by page basis
Angius
Angius2y ago
Or place it between <script> tags That original function doesn't take any variables
Gage
Gage2y ago
yeah it does, it takes the text area's string as a variable that parameter then converts into a mp3
Angius
Angius2y ago
It literally doesn't take any variables
Gage
Gage2y ago
what are you saying
Angius
Angius2y ago
List of arguments is empty
Angius
Angius2y ago
Gage
Gage2y ago
I just told you I don't know java script
Angius
Angius2y ago
You're gonna have a hard time, then
Gage
Gage2y ago
so then show me that's why I posted in help lmfao
Angius
Angius2y ago
This server isn't for spoonfeeding
Gage
Gage2y ago
jesus christ
Angius
Angius2y ago
I can help you, I won't give you a solution straight
Gage
Gage2y ago
telling me how to pass parameters is not spoon feeding just leave at this point
Angius
Angius2y ago
It works exactly as in C#
Gage
Gage2y ago
fuck you
Accord
Accord2y ago
✅ This post has been marked as answered!
Angius
Angius2y 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
More Posts