Code Monkey home page Code Monkey logo

spoken's Introduction

Text-to-Speech and Speech-to-Text for Artificial Intelligence and Chatbot Apps

Spoken is a free SDK for voice controlled apps. Improve your user's experience with easy to use Human Interface.

  • Zero GUI app.
  • Hands-free app interface.
  • Help blind and low-vision users gain independence.

Install Spoken NPM Package

NPM Module Location: https://www.npmjs.com/package/spoken

npm i spoken

Import Spoken into your App

You can import the spoken module in your app easily using the following example.

import spoken from './node_modules/spoken/build/spoken.js';
spoken.say('Should I turn the hallway light on?').then( speech => {
    spoken.listen().then( transcript =>
        console.log("Answer: " + transcript) )
} )

You may be looking for legacy import statements like this. Make sure to use the nomodule attribute on the <script> tag if you are also using import spoken.

<script nomodule src="https://stephenlb.github.io/spoken/spoken.js"></script>

Build an 80's Chatbot with an NPM Package

How to build a voice-controlled intelligent chatbot who comprehends human speech and responses accordingly and naturally!

Add Voice Controls to your OBS Twitch and YouTube Live Streams

Learn how we built an OBS Plugin that adds Subtitles to your Live Stream.

Add Subtitles to your Twitch stream! Easy OBS integration. Plugins should be easy to make! And for OBS, this is true. Hurray! The best way by far, my opinion, is using OBS Browser Sources.

App Ideas

You can imagine many new possible apps using this SDK.

  • Writing documents with your voice.
  • Driver safe hands-free mode.
  • Record meeting notes.
  • IoT Voice Control Commands.
  • Voice controlled games.

Voice Controlled Apps

Example Usage Pattern

You can prompt the user with a synthetic voice. And then you can speak the answer and capture the voice transcript. With a few lines of code, you can have a hands-free voice app.

Download package from NPM.

npm i spoken

Include package on your app page.

<script src="https://stephenlb.github.io/spoken/spoken.js"></script>

Access spoken global in your app.

spoken.say('Should I turn the hallway light on?').then( speech => {
    spoken.listen().then( transcript =>
        console.log("Answer: " + transcript) )
} )

ES6 Modules / Webpack Import Example

If you are looking to import

<script nomodule src="./spoken.js"></script>
<script type="module">
    import spoken from './build/spoken.js';
    spoken.say('Hello there!');
</script>

Code Playground

Playground URL: https://stephenlb.github.io/spoken/

You can test the code right now in your Chrome browser. Click the playground link above to try it out.

Text-to-Speech and Speech-to-Text

Turn Speech into Text and Text into Speech

Compatible on Android / iOS / Linux / Windows / MacOS.

Spoken is a Google Chrome Voice App SDK. This SDK allows you to easily call Voice APIs to turn Text to Speech and Speech to Text. The library has no dependencies. This SDK is only for Google Chrome apps on Mobile and Web.

Compatible with Electron (desktop), Ionic, PhoneGap/Cordova, React, Angular, etc. This works on Mobile Chrome.

Currently there is support for Google Chrome. And if you are looking to deploy as a mobile app, this should work 👌.

Text-to-Speech

Synthetic voices are pretty good these days. You can still tell they are robot voices.

Turn text into real-world spoken voice. The voice is synthetic. You can pick from a few different voices too.

// Hello World
spoken.say('Hello World.');

// Say a quick message as Guy Fieri
spoken.say( 'Looks like your on a trip to flavor town.', 'Daniel' );

// Speak with Damayanti's voice
spoken.say( 'I am princess of the Vidarbha Kingdom.', 'Damayanti' );

Promises and Async/Await

This SDK Supports modern async programming.

// Promise
spoken.say('Hello World.').then( v => console.log('Done talking.') );

// Async/Await
await spoken.say('Hello World.');
console.log('Done talking.');

Text-to-Speech Voice Selection Library

Synthetic voices are selectable using the spoken.voices method. There is a default voice that is included. You may want to pick a different voice. The following examples show you how to select a differnt voice.

// List of voices supported on platform
console.log( await spoken.voices() );

// List of voices with promise callback
spoken.voices().then( voices => console.log(voices) );

By default your language is auto-detected for you from navigator.language attribute. You can override this behavior using the following example.

Get list of English voices.

// List of English Speaking Voices
spoken.recognition.language = navigator.language || 'en-US';
let voices = (await spoken.voices()).filter( v => !v.lang.indexOf('en') );

// Use the First Voice
spoken.say( 'Welcome to flavor town.', voices[0] );

Sample the list of English voices.

// Speak with each English voice to sample your favorites
(await spoken.voices())
    .filter( voice => voice.lang.indexOf('en') == 0 )
    .map( voice => voice.name )
    .forEach( voice =>
        spoken.say( 'Welcome to flavor town.', voice ).then(
            speech => console.log(speech.voice.name)
        )
    );

Speech-to-Text

Must use HTTPS to access microphone.

You need an HTTPS (TLS) File Server. To start a local secure file server:

python <(curl -L https://goo.gl/LiW3lp)

Then open your browser and point it to your file in the directory you ran the python HTTPS server.

open https://0.0.0.0:4443/index.html

This is a Simple Python HTTPS Secure Server https://gist.github.com/stephenlb/2e19d98039469b9d0134

We posted an answer on StackOverflow WebRTC HTTPS. This will get you started testing on your laptop.

Turn your spoken words into text using the listen() method. You will want to also take advantage of the real-time speech detection using the spoken.listen.on.partial() event. This allows you to display the current transcription before your utterance is finished.

First you should check to see if the browser has access to the Speech-to-Text capability.

const available = spoken.listen.available();
if (available) console.log('Hurray voice transcription is available!');

The following will allow you to capture the full transcription of an utterance spoken into your microphone. The results can be used to send to a chatbot API.

// Async/Await
console.log(await spoken.listen());

// or Promise style
spoken.listen()
    .then( transcript => console.log(transcript)     )
    .catch(     error => console.warn(error.message) )

There can only be one concurrent listener. You can catch for this.

// We can only have one concurrent listener.
// So you can catch if there is an error.
spoken.listen()
    .then( transcript => console.log(transcript)     )
    .catch(     error => console.warn(error.message) )

Capture live "real-time" transcription as you speak.

spoken.listen.on.partial( ts => console.log(ts) );
spoken.listen()
    .then(     ts => console.log("Partial: " + ts) )
    .catch( error => console.warn(error.message)   )

Additional voice transcription events.

spoken.listen.on.start( voice => { console.log('Started Listening') } );
spoken.listen.on.end(   voice => { console.log('Ended Listening')   } );
spoken.listen.on.error( voice => { console.log('Error Listening')   } );

Stop listening.

spoken.listen.stop();

Continuous Listening Example

Writing a document with your voice or chatting with your friend hands-free is possible when you enable continuous listening mode.

spoken.listen.on.end(continueCapture);
spoken.listen.on.error(continueCapture);

startCapture();

function startCapture() { 
    spoken.listen({ continuous : true }).then( transcript =>
        console.log("Captured transcript: " + transcript)
    ).catch( e => true );
}

async function continueCapture() {
    await spoken.delay(300);
    if (spoken.recognition.continuous) startCapture();
}

function stopCapture() {
    spoken.recognition.continuous = false;
    spoken.listen.stop();
}

spoken's People

Contributors

stephenlb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

spoken's Issues

Unexpected ending of recording during document recording

Hi Stephen,

thanks for your great work on this package.

I'm using it to write documents via dictation.
I have encountered the problem, that after a while the spoken.listen() function seems to automatically stop. No error is thrown.

It really hinders me during dictation.

Do you have any idea why this happens?

Not working in Firefox

Hi Stephen,

Love spoken, it is both the best of any package that I've used at listening to voice and properly translate, as well as easy to use code. However right now it is not working in Firefox. This might be a more general problem with Firefox itself but was wanted to let you know. This is the error I am getting:

TypeError: recognition.start is not a function[Learn More] spoken.js:68:20

Failed to run in electron environment.

When running in a test environment for Electron, spoken runs into an error quickly. Here is the code used.

spoken.listen.on.start( voice => { console.log('Started Listening') } );
spoken.listen.on.end(   voice => { console.log('Ended Listening')   } );
spoken.listen.on.error( voice => { console.log('Error Listening', voice)   } );
spoken.listen.on.partial( ts => console.log(ts) );
spoken.listen()
    .then(     ts => console.log("Partial: " + ts) )
    .catch( error => console.warn(error.message)   )

I then received the following error.

bubbles: false
cancelBubble: false
cancelable: false
composed: false
currentTarget: SpeechRecognition {grammars: SpeechGrammarList, lang: "en-US", continuous: false, interimResults: true, maxAlternatives: 1, …}
defaultPrevented: false
error: "network"
eventPhase: 0
isTrusted: true
message: ""
path: []
returnValue: true
srcElement: SpeechRecognition {grammars: SpeechGrammarList, lang: "en-US", continuous: false, interimResults: true, maxAlternatives: 1, …}
target: SpeechRecognition {grammars: SpeechGrammarList, lang: "en-US", continuous: false, interimResults: true, maxAlternatives: 1, …}
timeStamp: 472.00499998871237
type: "error"

I hope you can get back to me.

Error!

const recognition = new webkitSpeechRecognition();
^

ReferenceError: webkitSpeechRecognition is not defined

React Native

Hi,

Do you know if it works with React Native? I built a simple app and imported your lib with spoken.say('Hello there!');, but when I run in the android smartphone, it is not returning sound or any errors.

Thanks,
Phillip.

Voices && Spoken.say

I believe only the standard English voice works now.

The others, even in your test demo repo, doesn't work anymore.

Therefore it won't work for other languages/voices either.

Not sure if it's an update to the Web Speech API or the Chrome browser.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.