Spaces:
Running
Running
Create app.js
Browse files- templates/app.js +40 -0
templates/app.js
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var app = {
|
2 |
+
init: function() {
|
3 |
+
// Get the elements we need
|
4 |
+
var textInput = $("#text-input");
|
5 |
+
var synthesizeButton = $("#synthesize-button");
|
6 |
+
var closeButton = $("#close-button");
|
7 |
+
|
8 |
+
// Add click events to the buttons
|
9 |
+
synthesizeButton.on('click', function() {
|
10 |
+
// Get the text to synthesize
|
11 |
+
var text = textInput.val();
|
12 |
+
|
13 |
+
// Make a request to the FastAPI server
|
14 |
+
$.ajax({
|
15 |
+
url: '/synthesize',
|
16 |
+
method: 'POST',
|
17 |
+
data: {
|
18 |
+
text: text
|
19 |
+
},
|
20 |
+
success: function(response) {
|
21 |
+
// Play the synthesized audio
|
22 |
+
var audio = new Audio(response.audio_url);
|
23 |
+
audio.play();
|
24 |
+
},
|
25 |
+
error: function(error) {
|
26 |
+
console.log(error);
|
27 |
+
}
|
28 |
+
});
|
29 |
+
});
|
30 |
+
|
31 |
+
closeButton.on('click', function() {
|
32 |
+
// Close the window
|
33 |
+
window.close();
|
34 |
+
});
|
35 |
+
}
|
36 |
+
};
|
37 |
+
|
38 |
+
$(document).ready(function() {
|
39 |
+
app.init();
|
40 |
+
});
|