Added TTS web plugin

This commit is contained in:
Fabio Manganiello 2018-04-16 14:38:08 +02:00
parent 607ec2812c
commit 40d1b7481a
3 changed files with 93 additions and 0 deletions

View file

@ -0,0 +1,9 @@
#tts-container {
max-width: 60em;
margin: 3em auto;
}
#tts-form input[type=text] {
width: 100%;
}

View file

@ -0,0 +1,65 @@
$(document).ready(function() {
var $container = $('#tts-container'),
$ttsForm = $('#tts-form');
var execute = function(request, onSuccess, onError, onComplete) {
request['target'] = 'localhost';
return $.ajax({
type: 'POST',
url: '/execute',
contentType: 'application/json',
dataType: 'json',
data: JSON.stringify(request),
complete: function() {
if (onComplete) {
onComplete();
}
},
error: function(xhr, status, error) {
if (onError) {
onError(xhr, status, error);
}
},
success: function(response, status, xhr) {
if (onSuccess) {
onSuccess(response, status, xhr);
}
},
beforeSend: function(xhr) {
if (window.token) {
xhr.setRequestHeader('X-Token', window.token);
}
},
});
};
var initBindings = function() {
$ttsForm.on('submit', function(event) {
var formData = $(this).serializeArray().reduce(function(obj, item) {
var value = item.value.trim();
if (value.length > 0) {
obj[item.name] = item.value;
}
return obj;
}, {});
execute(
{
type: 'request',
action: 'tts.say',
args: formData,
}
);
return false;
});
};
var init = function() {
initBindings();
};
init();
});

View file

@ -0,0 +1,19 @@
<script type="text/javascript" src="{{ url_for('static', filename='js/tts.js') }}"></script>
<link rel="stylesheet" href="{{ url_for('static', filename='css/tts.css') }}"></script>
<div class="row" id="tts-container">
<form action="#" id="tts-form">
<div class="eight columns">
<input type="text" name="phrase" placeholder="Text to say">
</div>
<div class="three columns">
<input type="text" name="lang" placeholder="Lang code">
</div>
<div class="one column">
<button type="submit">
<i class="fa fa-microphone"></i>
</button>
</div>
</form>
</div>