-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs.js
More file actions
106 lines (67 loc) · 2.3 KB
/
js.js
File metadata and controls
106 lines (67 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
let bouton = false;
let compteur = 1;
$('.switch').click(function(){
if ($('.selected').find('input').val().length > 1 && bouton) {
$('.interview').append('<p><span class="name">' + $('.selected').find('input').val() + '</span>' + '<span class="final" id="txt'+compteur+'">'+ final_transcript +'</span>' +'<span class="mic" onclick="speak('+ compteur +')"><i class="material-icons">headset_mic</i></span></p>')
$('#1').toggleClass('selected');
$('#2').toggleClass('selected');
final_transcript = "";
$('.switch').attr("disabled", "disabled");
bouton = false;
compteur ++;
}
});
var final_transcript = '';
var recognizing = false;
if ('webkitSpeechRecognition' in window) {
var recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.interimResults = true;
recognition.onstart = function() {
recognizing = true;
};
recognition.onerror = function(event) {
console.log(event.error);
};
recognition.onend = function() {
recognizing = false;
};
recognition.onresult = function(event) {
var interim_transcript = '';
for (var i = event.resultIndex; i < event.results.length; ++i) {
if (event.results[i].isFinal) {
final_transcript += event.results[i][0].transcript;
} else {
interim_transcript += event.results[i][0].transcript;
}
$('.current').html('<p>' + interim_transcript + '</p>')
}
final_transcript = capitalize(final_transcript);
console.log(final_transcript);
bouton = true;
};
}
var two_line = /\n\n/g;
var one_line = /\n/g;
function linebreak(s) {
return s.replace(two_line, '<p></p>').replace(one_line, '<br>');
}
function capitalize(s) {
return s.replace(s.substr(0,1), function(m) { return m.toUpperCase(); });
}
function startDictation(event) {
final_transcript = '';
recognition.lang = 'fr-FR';
recognition.start();
}
startDictation();
function speak(id){
let text = $('#txt' + id).html()
console.log(id);
let synth = window.speechSynthesis;
let voiceSelect = "Microsoft Hortense Desktop - French (fr-FR)"
let utterThis = new SpeechSynthesisUtterance(text);
utterThis.pitch = 1
utterThis.rate = 1
synth.speak(utterThis);
}