From 3f6e46619a6ba65083bcee8f2a42709f4cf410c6 Mon Sep 17 00:00:00 2001 From: Christopher de Beer Date: Mon, 28 Nov 2011 15:12:26 +0000 Subject: [PATCH 01/20] made node compatability changes in pre.js and post.js, added package.json and amended readme.markdown --- README.markdown | 29 ++++++++++++++++++++++++++++- package.json | 18 ++++++++++++++++++ src/post.js | 17 ++++++++++++----- src/pre.js | 10 +++++++++- 4 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 package.json diff --git a/README.markdown b/README.markdown index 7a3891f..133c829 100644 --- a/README.markdown +++ b/README.markdown @@ -3,11 +3,13 @@ speak.js A port of the eSpeak speech synthesizer from C++ to JavaScript using Emscripten. -Enables text-to-speech on the web using only JavaScript and HTML5. +Enables text-to-speech on the web using only JavaScript and HTML5. or within Node.js as a module. **Online demo**: http://syntensity.com/static/espeak.html + + Usage ----- @@ -31,6 +33,20 @@ See helloworld.html for a simple 'hello world', and demo.html for a more detailed example. +Node.js Installation +--------------------- + + +To install speak.js from NPM, do the following + `npm install node-speak` + +Then require it in your app like so + `var speak = require("node-speak");` + +Using speak,js in Node, will **Require** you to use a callback, see **Custom Callbacks** below for more info. + + + Options ------- @@ -47,6 +63,7 @@ available options are: build speak.js to include the proper data. See Language Support below) (default: en/en-us) * wordgap: Additional gap between words in 10 ms units (default: 0) + * callback: You can define a custom callback that will get passed the outputted base64 encoded audio data uri, see **Custom Callbacks** below. For example @@ -54,6 +71,16 @@ For example will talk in a very high-pitched voice. +**Custom Callbacks** + +if you would like to define your own response to the generated audio data, you can define a custom callback, by setting the `callback` in the options, like so: + + `speak('hello world', { callback: function (src) { + // do whatever you want with the returned data: "src" + }})` + + + Building -------- diff --git a/package.json b/package.json new file mode 100644 index 0000000..04aa606 --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "author": "Christopher de Beer (https://github.com/christopherdebeer)", + "name": "node-speak", + "description": "TTS (Text to Speech) for Node and the browser", + "version": "0.0.3", + "keywords": ["TTS", "Audio", "Speech", "Talk", "Text to Speech"] + "homepage": "https://github.com/christopherdebeer/speak.js", + "repository": { + "type": "git", + "url": "git://github.com/christopherdebeer/speak.js.git" + }, + "main": "speak.js", + "engines": { + "node": "~0.6.2" + }, + "dependencies": {}, + "devDependencies": {} +} diff --git a/src/post.js b/src/post.js index 1178342..1bf7a15 100644 --- a/src/post.js +++ b/src/post.js @@ -16,6 +16,13 @@ function speak(text, args) { args = args || {}; + + // assign callback either the default action, or a custom callback if specified by the user + // e.g. speak("hello world", {callback: function(src){ console.log("Custom handling of returned 'src'", src ); }}) + callback = args.callback || function (src) { + document.getElementById("audio").innerHTML=("