uncommitted changes to frontend

This commit is contained in:
Brandon Thomas committed 2020-05-10 22:42:07 -04:00
1 parent 8625daa59d
commit 7b2eff1387
1 file changed
+49
+49
View File
@@ -0,0 +1,49 @@
import Howl from 'howler';
/// Requests to the backend.
class TtsRequest {
text: String
speaker: String
constructor(text: String) {
this.text = text;
// LJSpeech dataset from Keith Ito & LibriVox, spoken by Linda Johnson.
this.speaker = 'linda';
}
}
class TtsResponse {
text: string
howl: Howl
constructor(text: string, howl: Howl) {
this.text = text;
this.howl = howl;
}
}
let makeTtsRequest = (sentence: string): Promise<TtsResponse> => {
const request = new TtsRequest(sentence);
const url = `/tts`;
return fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(request),
})
.then(res => res.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const howlSound = new Howl.Howl({
src: [url],
format: 'wav',
});
return new TtsResponse(sentence, howlSound);
});
}
export {TtsRequest, TtsResponse, makeTtsRequest};