mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-15 14:22:14 +00:00
uncommitted changes to frontend
This commit is contained in:
1 parent
8625daa59d
commit
7b2eff1387
1 file changed
+49
@@ -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};
|
||||
Reference in new issue
Block a user