Skip to content

Commit

Permalink
more txt to speech work
Browse files Browse the repository at this point in the history
  • Loading branch information
jondubin committed Jun 27, 2015
1 parent 91bb96b commit 7afeb8e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
4 changes: 1 addition & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var routes = require('./routes/index');
var users = require('./routes/users');

var app = express();

Expand All @@ -23,7 +22,6 @@ app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
Expand Down Expand Up @@ -57,4 +55,4 @@ app.use(function(err, req, res, next) {
});


module.exports = app;
module.exports = app;
32 changes: 32 additions & 0 deletions public/js/speech.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
$(document).ready(function () {
if ('webkitSpeechRecognition' in window) {
var recognition = new webkitSpeechRecognition();
var final_transcript = '';
recognition.continuous = true;
recognition.interimResults = true;
//var interim_transcript = '';

recognition.onresult = function (event) {
var interim_transcript = '';
for (var i = event.resultIndex; i < event.results.length; ++i) {
console.log(event.results);
if (i === event.results.length - 1) {
console.log(event.results[i][0].transcript);
console.log(event.results[i][0].confidence);
}
if (event.results[i].isFinal) {
final_transcript += event.results[i][0].transcript;
} else {
interim_transcript += event.results[i][0].transcript;
}
}

$('#interim_span').html(interim_transcript);
$('#final_span').html(final_transcript);
};

document.querySelector('button').addEventListener('click', function () {
recognition.start();
});
}
});
5 changes: 5 additions & 0 deletions views/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ extends layout
block content
h1= title
p Welcome to #{title}
button Start
input(type="text", style="width: 100%")
span#final_span.final
hr
span#interim_span.interim
4 changes: 3 additions & 1 deletion views/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
script(src="//code.jquery.com/jquery-1.11.3.min.js")
script(src="/js/speech.js")
body
block content
block content

0 comments on commit 7afeb8e

Please sign in to comment.