ScratchData LogoScratchData
Back to Tagme's profile

[Open-Concept] Virtual A.I.

TATagme•Created January 18, 2017
[Open-Concept] Virtual A.I.
0
0
8 views
View on Scratch

Instructions

(function(ext) { // TODO: public repo + documentation + samples // GH pages $.ajax({ async:false, type:'GET', url:'https://cdn.firebase.com/js/client/2.2.4/firebase.js', data:null, success: function(){fb = new Firebase('https://scratchx.firebaseio.com');console.log('ok');}, //Create a firebase reference dataType:'script' }); window['temp'] = 0; // init // Cleanup function when the extension is unloaded ext._shutdown = function() {}; // Status reporting code // Use this to report missing hardware, plugin or unsupported browser ext._getStatus = function() { return {status: 2, msg: 'Ready'}; }; ext.broadcast = function(name) { if (name.length > 0){ // blank broadcasts break firebase - not nice. window['sent-' + name] = Math.random(); // HUGE thanks to the folks at White Mountain Science for fixing the multiple broadcast bug! (lines 32-40) fb.child('broadcasts/' + name).set(window['sent-' + name]); //Change value of broadcast so other clients get an update } }; ext.mesh_hat = function(name) { fb.child('broadcasts/' + name).on('value', function(snap){window['new-' + name] = snap.val();console.log(name);}); // Make sure broadcasts are unique (don't activate twice) if(window['last-' + name] != window['new-' + name] && window['new-' + name] != window['sent-' + name]){ window['last-' + name] = window['new-' + name]; return true; } else { return false; } } // Block and block menu descriptions var descriptor = { blocks: [ [' ', 'mesh broadcast %s', 'broadcast'], ['h', 'when I receive mesh %s', 'mesh_hat'] ], url: 'http://technoboy10.tk/mesh' }; // Register the extension ScratchExtensions.register('Mesh', descriptor, ext); })({});

Description

/* Extension using the JavaScript Speech API for text to speech */ /* Sayamindu Dasgupta <sayamindu@media.mit.edu>, April 2014 */ new (function() { var ext = this; /*function _get_voices() { var ret = []; var voices = speechSynthesis.getVoices(); for(var i = 0; i < voices.length; i++ ) { ret.push(voices[i].name); console.log(voices.toString()); } return ret; } ext.set_voice = function() { };*/ 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._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: [ //['', 'set voice to %m.voices', 'set_voice', ''], ['w', 'speak %s', 'speak_text', 'Hello!'], ], /*menus: { voices: _get_voices(), },*/ }; ScratchExtensions.register('Text to Speech', descriptor, ext); })();

Project Details

Project ID140510705
CreatedJanuary 18, 2017
Last ModifiedJanuary 12, 2019
SharedDecember 7, 2018
Visibilityvisible
CommentsAllowed