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