-
Notifications
You must be signed in to change notification settings - Fork 0
/
extensions.js
51 lines (51 loc) · 2.47 KB
/
extensions.js
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
javascript: new (function () {
var ext = this; var recognized_speech = '';
ext.recognize_speech = function (callback) {
var recognition = new webkitSpeechRecognition();
recognition.onresult = function (event) {
if (event.results.length > 0) {
recognized_speech = event.results[0][0].transcript;
if (typeof callback == "function") callback()
}
};
recognition.start()
};
ext.recognized_speech = function () {
return recognized_speech
}; ext.STTenabled = function () {
return window.webkitSpeechRecognition != undefined
}; ext._shutdown = function () { };
ext._getStatus = function () {
if (window.webkitSpeechRecognition === undefined) {
return {
status: 1, msg: 'Your browser does not support speech recognition. Try using Google Chrome.'
}
} return {
status: 2, msg: 'Ready'
}
};
var descriptor = { blocks: [['w', 'wait and recognize speech', 'recognize_speech'], ['r', 'recognized speech', 'recognized_speech'], ['b', 'speech to text enabled', 'STTenabled']] };
ScratchExtensions.register('Speech To Text', descriptor, ext)
})(); new (function () {
var ext = this; ext.speak_text = function (text, callback) {
var u = new SpeechSynthesisUtterance(text.toString());
u.onend = function (event) {
if (typeof callback == "function") callback()
};
speechSynthesis.speak(u)
};
ext.TTSenabled = function () {
return window.SpeechSynthesisUtterance != undefined
}; ext._shutdown = function () { }; ext._getStatus = function () {
if (window.SpeechSynthesisUtterance === undefined) {
return {status: 1, msg: 'Your browser does not support text to speech. Try using Google Chrome or Safari.' }
} return { status: 2, msg: 'Ready' }
};
var descriptor = { blocks: [['w', 'speak %s', 'speak_text', 'Hello!'], ['b', 'text to speech enabled', 'TTSenabled']], };
ScratchExtensions.register('Text to Speech', descriptor, ext) })(); new (function () {
var ext = this; ext._shutdown = function () { };
ext._getStatus = function () {
return { status: 2, msg: 'Ready' } };
ext.trueBlock = function () {return true };
var descriptor = { blocks: [['b', 'enabled?', 'trueBlock'],] };
ScratchExtensions.register('extension registered?', descriptor, ext) })();