mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Working on speech rec
This commit is contained in:
parent
9dd2ab43c2
commit
dcee9285d9
@ -2463,6 +2463,7 @@ $LANG = array(
|
|||||||
'import_complete' => 'Your import has successfully completed.',
|
'import_complete' => 'Your import has successfully completed.',
|
||||||
'confirm_account_to_import' => 'Please confirm your account to import data.',
|
'confirm_account_to_import' => 'Please confirm your account to import data.',
|
||||||
'import_started' => 'Your import has started, we\'ll send you an email once it completes.',
|
'import_started' => 'Your import has started, we\'ll send you an email once it completes.',
|
||||||
|
'listening' => 'Listening...',
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,6 +1,20 @@
|
|||||||
<i class="fa fa-microphone form-control-feedback" style="font-size:16px;padding-top:8px" aria-hidden="true"></i>
|
<i id="microphone" class="fa fa-microphone form-control-feedback"
|
||||||
|
style=""
|
||||||
|
onclick="startButton(event)" aria-hidden="true"></i>
|
||||||
|
|
||||||
|
<style type="text/css">
|
||||||
|
#microphone {
|
||||||
|
font-size:16px;
|
||||||
|
padding-top:8px;
|
||||||
|
cursor:pointer;
|
||||||
|
pointer-events:auto;
|
||||||
|
color:#888;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
// https://developers.google.com/web/updates/2013/01/Voice-Driven-Web-Apps-Introduction-to-the-Web-Speech-API
|
||||||
$(function() {
|
$(function() {
|
||||||
$('#search').keypress(function(event) {
|
$('#search').keypress(function(event) {
|
||||||
if (event.keyCode === 13) {
|
if (event.keyCode === 13) {
|
||||||
@ -90,55 +104,38 @@
|
|||||||
if (!('webkitSpeechRecognition' in window)) {
|
if (!('webkitSpeechRecognition' in window)) {
|
||||||
upgrade();
|
upgrade();
|
||||||
} else {
|
} else {
|
||||||
//start_button.style.display = 'inline-block';
|
|
||||||
var recognition = new webkitSpeechRecognition();
|
var recognition = new webkitSpeechRecognition();
|
||||||
recognition.continuous = true;
|
recognition.continuous = false;
|
||||||
recognition.interimResults = true;
|
recognition.interimResults = true;
|
||||||
|
|
||||||
recognition.onstart = function() {
|
recognition.onstart = function() {
|
||||||
recognizing = true;
|
recognizing = true;
|
||||||
showInfo('info_speak_now');
|
|
||||||
//start_img.src = '/intl/en/chrome/assets/common/images/content/mic-animate.gif';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
recognition.onerror = function(event) {
|
recognition.onerror = function(event) {
|
||||||
|
$('.fa-microphone').show();
|
||||||
|
$('#search').val('');
|
||||||
if (event.error == 'no-speech') {
|
if (event.error == 'no-speech') {
|
||||||
//start_img.src = '/intl/en/chrome/assets/common/images/content/mic.gif';
|
|
||||||
showInfo('info_no_speech');
|
|
||||||
ignore_onend = true;
|
ignore_onend = true;
|
||||||
}
|
}
|
||||||
if (event.error == 'audio-capture') {
|
if (event.error == 'audio-capture') {
|
||||||
//start_img.src = '/intl/en/chrome/assets/common/images/content/mic.gif';
|
|
||||||
showInfo('info_no_microphone');
|
|
||||||
ignore_onend = true;
|
ignore_onend = true;
|
||||||
}
|
}
|
||||||
if (event.error == 'not-allowed') {
|
if (event.error == 'not-allowed') {
|
||||||
if (event.timeStamp - start_timestamp < 100) {
|
|
||||||
showInfo('info_blocked');
|
|
||||||
} else {
|
|
||||||
showInfo('info_denied');
|
|
||||||
}
|
|
||||||
ignore_onend = true;
|
ignore_onend = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
recognition.onend = function() {
|
recognition.onend = function() {
|
||||||
recognizing = false;
|
recognizing = false;
|
||||||
|
$('.fa-microphone').show();
|
||||||
|
$('#search').val('');
|
||||||
if (ignore_onend) {
|
if (ignore_onend) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//start_img.src = '/intl/en/chrome/assets/common/images/content/mic.gif';
|
|
||||||
if (!final_transcript) {
|
if (!final_transcript) {
|
||||||
showInfo('info_start');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
showInfo('');
|
|
||||||
if (window.getSelection) {
|
|
||||||
window.getSelection().removeAllRanges();
|
|
||||||
var range = document.createRange();
|
|
||||||
range.selectNode(document.getElementById('final_span'));
|
|
||||||
window.getSelection().addRange(range);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
recognition.onresult = function(event) {
|
recognition.onresult = function(event) {
|
||||||
@ -157,16 +154,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
final_transcript = capitalize(final_transcript);
|
final_transcript = capitalize(final_transcript);
|
||||||
//final_span.innerHTML = linebreak(final_transcript);
|
|
||||||
//interim_span.innerHTML = linebreak(interim_transcript);
|
var value = final_transcript || interim_transcript;
|
||||||
console.log('final_span: %s', linebreak(final_transcript));
|
var $search = document.getElementById('search');
|
||||||
console.log('interim_span: %s', linebreak(interim_transcript));
|
$search.value = value;
|
||||||
|
$search.scrollLeft = $search.scrollWidth;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function upgrade() {
|
function upgrade() {
|
||||||
start_button.style.visibility = 'hidden';
|
$('.fa-microphone').hide();
|
||||||
showInfo('info_upgrade');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var two_line = /\n\n/g;
|
var two_line = /\n\n/g;
|
||||||
@ -181,35 +178,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function startButton(event) {
|
function startButton(event) {
|
||||||
|
$('.fa-microphone').hide();
|
||||||
|
$('#search').val("{{ trans('texts.listening') }}");
|
||||||
if (recognizing) {
|
if (recognizing) {
|
||||||
recognition.stop();
|
recognition.stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final_transcript = '';
|
final_transcript = '';
|
||||||
recognition.lang = select_dialect.value;
|
recognition.lang = 'en-US';
|
||||||
recognition.start();
|
recognition.start();
|
||||||
ignore_onend = false;
|
ignore_onend = false;
|
||||||
final_span.innerHTML = '';
|
|
||||||
interim_span.innerHTML = '';
|
|
||||||
//start_img.src = '/intl/en/chrome/assets/common/images/content/mic-slash.gif';
|
|
||||||
showInfo('info_allow');
|
|
||||||
start_timestamp = event.timeStamp;
|
start_timestamp = event.timeStamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
function showInfo(s) {
|
|
||||||
console.log('Info: ' + s);
|
|
||||||
/*
|
|
||||||
if (s) {
|
|
||||||
for (var child = info.firstChild; child; child = child.nextSibling) {
|
|
||||||
if (child.style) {
|
|
||||||
child.style.display = child.id == s ? 'inline' : 'none';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
info.style.visibility = 'visible';
|
|
||||||
} else {
|
|
||||||
info.style.visibility = 'hidden';
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user