2017-04-04 15:08:28 +02:00
|
|
|
|
<i id="microphone" class="fa fa-microphone form-control-feedback"
|
2018-02-19 11:21:51 +01:00
|
|
|
|
title="Say "new invoice for [client]" or "show me [client]'s archived payments""
|
|
|
|
|
data-toggle="tooltip" data-placement="bottom"
|
|
|
|
|
onclick="onMicrophoneClick()" aria-hidden="true"></i>
|
2017-04-04 15:08:28 +02:00
|
|
|
|
|
|
|
|
|
<style type="text/css">
|
2018-02-19 11:21:51 +01:00
|
|
|
|
#microphone {
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
padding-top: 8px;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
pointer-events: auto;
|
|
|
|
|
color: #888;
|
|
|
|
|
}
|
2017-04-04 15:57:33 +02:00
|
|
|
|
|
2018-02-19 11:21:51 +01:00
|
|
|
|
#microphone:hover {
|
|
|
|
|
color: black;
|
|
|
|
|
}
|
2017-04-04 15:08:28 +02:00
|
|
|
|
</style>
|
2017-04-04 11:54:38 +02:00
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
2017-04-04 15:08:28 +02:00
|
|
|
|
|
2018-02-19 11:21:51 +01:00
|
|
|
|
// https://developers.google.com/web/updates/2013/01/Voice-Driven-Web-Apps-Introduction-to-the-Web-Speech-API
|
2017-04-04 11:54:38 +02:00
|
|
|
|
|
2018-02-19 11:21:51 +01:00
|
|
|
|
/*
|
|
|
|
|
var langs =
|
|
|
|
|
[['Afrikaans', ['af-ZA']],
|
|
|
|
|
['Bahasa Indonesia',['id-ID']],
|
|
|
|
|
['Bahasa Melayu', ['ms-MY']],
|
|
|
|
|
['Català', ['ca-ES']],
|
|
|
|
|
['Čeština', ['cs-CZ']],
|
|
|
|
|
['Dansk', ['da-DK']],
|
|
|
|
|
['Deutsch', ['de-DE']],
|
|
|
|
|
['English', ['en-AU', 'Australia'],
|
|
|
|
|
['en-CA', 'Canada'],
|
|
|
|
|
['en-IN', 'India'],
|
|
|
|
|
['en-NZ', 'New Zealand'],
|
|
|
|
|
['en-ZA', 'South Africa'],
|
|
|
|
|
['en-GB', 'United Kingdom'],
|
|
|
|
|
['en-US', 'United States']],
|
|
|
|
|
['Español', ['es-AR', 'Argentina'],
|
|
|
|
|
['es-BO', 'Bolivia'],
|
|
|
|
|
['es-CL', 'Chile'],
|
|
|
|
|
['es-CO', 'Colombia'],
|
|
|
|
|
['es-CR', 'Costa Rica'],
|
|
|
|
|
['es-EC', 'Ecuador'],
|
|
|
|
|
['es-SV', 'El Salvador'],
|
|
|
|
|
['es-ES', 'España'],
|
|
|
|
|
['es-US', 'Estados Unidos'],
|
|
|
|
|
['es-GT', 'Guatemala'],
|
|
|
|
|
['es-HN', 'Honduras'],
|
|
|
|
|
['es-MX', 'México'],
|
|
|
|
|
['es-NI', 'Nicaragua'],
|
|
|
|
|
['es-PA', 'Panamá'],
|
|
|
|
|
['es-PY', 'Paraguay'],
|
|
|
|
|
['es-PE', 'Perú'],
|
|
|
|
|
['es-PR', 'Puerto Rico'],
|
|
|
|
|
['es-DO', 'República Dominicana'],
|
|
|
|
|
['es-UY', 'Uruguay'],
|
|
|
|
|
['es-VE', 'Venezuela']],
|
|
|
|
|
['Euskara', ['eu-ES']],
|
|
|
|
|
['Filipino', ['fil-PH']],
|
|
|
|
|
['Français', ['fr-FR']],
|
|
|
|
|
['Galego', ['gl-ES']],
|
|
|
|
|
['Hrvatski', ['hr_HR']],
|
|
|
|
|
['IsiZulu', ['zu-ZA']],
|
|
|
|
|
['Íslenska', ['is-IS']],
|
|
|
|
|
['Italiano', ['it-IT', 'Italia'],
|
|
|
|
|
['it-CH', 'Svizzera']],
|
|
|
|
|
['Lietuvių', ['lt-LT']],
|
|
|
|
|
['Magyar', ['hu-HU']],
|
|
|
|
|
['Nederlands', ['nl-NL']],
|
|
|
|
|
['Norsk bokmål', ['nb-NO']],
|
|
|
|
|
['Polski', ['pl-PL']],
|
|
|
|
|
['Português', ['pt-BR', 'Brasil'],
|
|
|
|
|
['pt-PT', 'Portugal']],
|
|
|
|
|
['Română', ['ro-RO']],
|
|
|
|
|
['Slovenščina', ['sl-SI']],
|
|
|
|
|
['Slovenčina', ['sk-SK']],
|
|
|
|
|
['Suomi', ['fi-FI']],
|
|
|
|
|
['Svenska', ['sv-SE']],
|
|
|
|
|
['Tiếng Việt', ['vi-VN']],
|
|
|
|
|
['Türkçe', ['tr-TR']],
|
|
|
|
|
['Ελληνικά', ['el-GR']],
|
|
|
|
|
['български', ['bg-BG']],
|
|
|
|
|
['Pусский', ['ru-RU']],
|
|
|
|
|
['Српски', ['sr-RS']],
|
|
|
|
|
['Українська', ['uk-UA']],
|
|
|
|
|
['한국어', ['ko-KR']],
|
|
|
|
|
['中文', ['cmn-Hans-CN', '普通话 (中国大陆)'],
|
|
|
|
|
['cmn-Hans-HK', '普通话 (香港)'],
|
|
|
|
|
['cmn-Hant-TW', '中文 (台灣)'],
|
|
|
|
|
['yue-Hant-HK', '粵語 (香港)']],
|
|
|
|
|
['日本語', ['ja-JP']],
|
|
|
|
|
['हिन्दी', ['hi-IN']],
|
|
|
|
|
['ภาษาไทย', ['th-TH']]];
|
|
|
|
|
*/
|
2017-04-04 11:54:38 +02:00
|
|
|
|
|
2018-02-19 11:21:51 +01:00
|
|
|
|
var final_transcript = '';
|
|
|
|
|
var recognizing = false;
|
|
|
|
|
var ignore_onend;
|
2017-04-04 11:54:38 +02:00
|
|
|
|
|
2018-02-19 11:21:51 +01:00
|
|
|
|
if (!('webkitSpeechRecognition' in window)) {
|
|
|
|
|
$('.fa-microphone').hide();
|
|
|
|
|
} else {
|
|
|
|
|
var recognition = new webkitSpeechRecognition();
|
|
|
|
|
recognition.continuous = false;
|
|
|
|
|
recognition.interimResults = true;
|
2017-04-04 11:54:38 +02:00
|
|
|
|
|
2018-02-19 11:21:51 +01:00
|
|
|
|
recognition.onstart = function() {
|
2017-04-04 11:54:38 +02:00
|
|
|
|
recognizing = true;
|
2018-02-19 11:21:51 +01:00
|
|
|
|
};
|
2017-04-04 11:54:38 +02:00
|
|
|
|
|
2018-02-19 11:21:51 +01:00
|
|
|
|
recognition.onerror = function(event) {
|
2017-04-04 15:08:28 +02:00
|
|
|
|
$('.fa-microphone').show();
|
|
|
|
|
$('#search').val('');
|
2017-04-04 11:54:38 +02:00
|
|
|
|
if (event.error == 'no-speech') {
|
2018-02-19 11:21:51 +01:00
|
|
|
|
ignore_onend = true;
|
2017-04-04 11:54:38 +02:00
|
|
|
|
}
|
|
|
|
|
if (event.error == 'audio-capture') {
|
2018-02-19 11:21:51 +01:00
|
|
|
|
ignore_onend = true;
|
2017-04-04 11:54:38 +02:00
|
|
|
|
}
|
|
|
|
|
if (event.error == 'not-allowed') {
|
2018-02-19 11:21:51 +01:00
|
|
|
|
ignore_onend = true;
|
2017-04-04 11:54:38 +02:00
|
|
|
|
}
|
2018-02-19 11:21:51 +01:00
|
|
|
|
};
|
2017-04-04 11:54:38 +02:00
|
|
|
|
|
2018-02-19 11:21:51 +01:00
|
|
|
|
recognition.onend = function() {
|
2017-04-04 11:54:38 +02:00
|
|
|
|
recognizing = false;
|
2017-04-04 15:08:28 +02:00
|
|
|
|
$('.fa-microphone').show();
|
2017-04-23 10:15:38 +02:00
|
|
|
|
if (ignore_onend || !final_transcript) {
|
2018-02-19 11:21:51 +01:00
|
|
|
|
$('#search').val('');
|
|
|
|
|
return;
|
2017-04-04 11:54:38 +02:00
|
|
|
|
}
|
2017-04-04 15:57:33 +02:00
|
|
|
|
$('#search-form').submit();
|
2018-02-19 11:21:51 +01:00
|
|
|
|
};
|
2017-04-04 11:54:38 +02:00
|
|
|
|
|
2018-02-19 11:21:51 +01:00
|
|
|
|
recognition.onresult = function(event) {
|
2017-04-04 11:54:38 +02:00
|
|
|
|
var interim_transcript = '';
|
|
|
|
|
if (typeof(event.results) == 'undefined') {
|
2018-02-19 11:21:51 +01:00
|
|
|
|
recognition.onend = null;
|
|
|
|
|
recognition.stop();
|
|
|
|
|
$('.fa-microphone').hide();
|
|
|
|
|
$('#search').val('');
|
|
|
|
|
return;
|
2017-04-04 11:54:38 +02:00
|
|
|
|
}
|
|
|
|
|
for (var i = event.resultIndex; i < event.results.length; ++i) {
|
2018-02-19 11:21:51 +01:00
|
|
|
|
if (event.results[i].isFinal) {
|
|
|
|
|
final_transcript += event.results[i][0].transcript;
|
|
|
|
|
} else {
|
|
|
|
|
interim_transcript += event.results[i][0].transcript;
|
|
|
|
|
}
|
2017-04-04 11:54:38 +02:00
|
|
|
|
}
|
|
|
|
|
final_transcript = capitalize(final_transcript);
|
2017-04-04 15:08:28 +02:00
|
|
|
|
var value = final_transcript || interim_transcript;
|
|
|
|
|
var $search = document.getElementById('search');
|
|
|
|
|
$search.value = value;
|
|
|
|
|
$search.scrollLeft = $search.scrollWidth;
|
2018-02-19 11:21:51 +01:00
|
|
|
|
};
|
|
|
|
|
}
|
2017-04-04 11:54:38 +02:00
|
|
|
|
|
2018-02-19 11:21:51 +01:00
|
|
|
|
var first_char = /\S/;
|
|
|
|
|
function capitalize(s) {
|
|
|
|
|
return s.replace(first_char, function(m) { return m.toUpperCase(); });
|
|
|
|
|
}
|
2017-04-04 11:54:38 +02:00
|
|
|
|
|
2018-02-19 11:21:51 +01:00
|
|
|
|
function onMicrophoneClick() {
|
|
|
|
|
if (!recognition) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-04-04 15:57:33 +02:00
|
|
|
|
|
2018-02-19 11:21:51 +01:00
|
|
|
|
$('.fa-microphone').hide();
|
|
|
|
|
$('#search').val("{{ trans('texts.listening') }}");
|
|
|
|
|
if (recognizing) {
|
2017-04-04 11:54:38 +02:00
|
|
|
|
recognition.stop();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-02-19 11:21:51 +01:00
|
|
|
|
final_transcript = '';
|
|
|
|
|
recognition.lang = 'en-US';
|
|
|
|
|
recognition.start();
|
|
|
|
|
ignore_onend = false;
|
|
|
|
|
}
|
2017-04-04 11:54:38 +02:00
|
|
|
|
|
|
|
|
|
</script>
|