{"id":14984402,"url":"https://github.com/stephenlb/spoken","last_synced_at":"2025-04-10T20:08:47.437Z","repository":{"id":57367741,"uuid":"136405456","full_name":"stephenlb/spoken","owner":"stephenlb","description":"Spoken - JavaScript Text-to-Speech and Speech-to-Text for AI Artificial Intelligence Apps","archived":false,"fork":false,"pushed_at":"2018-09-14T23:24:48.000Z","size":34,"stargazers_count":76,"open_issues_count":4,"forks_count":13,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-24T17:52:44.673Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://stephenlb.github.io/spoken/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stephenlb.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-07T01:32:58.000Z","updated_at":"2025-02-28T17:27:57.000Z","dependencies_parsed_at":"2022-08-23T20:10:23.466Z","dependency_job_id":null,"html_url":"https://github.com/stephenlb/spoken","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenlb%2Fspoken","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenlb%2Fspoken/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenlb%2Fspoken/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephenlb%2Fspoken/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stephenlb","download_url":"https://codeload.github.com/stephenlb/spoken/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248288350,"owners_count":21078903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T14:08:59.289Z","updated_at":"2025-04-10T20:08:47.412Z","avatar_url":"https://github.com/stephenlb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Text-to-Speech and Speech-to-Text for Artificial Intelligence and Chatbot Apps\n\nSpoken is a **free SDK** for voice controlled apps.\nImprove your user's experience with easy to use _Human Interface_.\n\n - Zero GUI app.\n - Hands-free app interface.\n - Help blind and low-vision users gain independence.\n\n### Install Spoken NPM Package\n\nNPM Module Location: https://www.npmjs.com/package/spoken\n\n```shell\nnpm i spoken\n```\n\n### Import Spoken into your App\n\nYou can import the spoken module in your app easily using the following example.\n\n```javascript\nimport spoken from './node_modules/spoken/build/spoken.js';\nspoken.say('Should I turn the hallway light on?').then( speech =\u003e {\n    spoken.listen().then( transcript =\u003e\n        console.log(\"Answer: \" + transcript) )\n} )\n```\n\nYou may be looking for legacy import statements like this.\nMake sure to use the `nomodule` attribute on the `\u003cscript\u003e` tag\nif you are also using `import spoken`.\n\n```html\n\u003cscript nomodule src=\"https://stephenlb.github.io/spoken/spoken.js\"\u003e\u003c/script\u003e\n```\n\n### Build an 80's Chatbot with an NPM Package\n\nHow to build a\n[voice-controlled intelligent chatbot](https://www.pubnub.com/blog/build-an-80s-chatbot-with-an-npm-package/)\nwho comprehends human speech and responses accordingly and naturally!\n\n### Add Voice Controls to your OBS Twitch and YouTube Live Streams\n\nLearn how we [built an OBS\nPlugin that adds Subtitles to your\nLive Stream](https://www.pubnub.com/developers/twitch-tv-obs-subtitles/).\n\nAdd Subtitles to your Twitch stream! Easy OBS integration.\nPlugins should be easy to make! And for OBS, this is true. Hurray!\nThe best way by far, my opinion, is using OBS Browser Sources.\n\n### App Ideas\n\nYou can imagine many new possible apps using this SDK.\n\n - Writing documents with your voice.\n - Driver safe hands-free mode.\n - Record meeting notes.\n - IoT Voice Control Commands.\n - Voice controlled games.\n\n![Voice Controlled Apps](https://i.imgur.com/tXJmwrN.gif)\n\n\n### Example Usage Pattern\n\nYou can prompt the user with a synthetic voice.\nAnd then you can speak the answer and capture the voice transcript.\nWith a few lines of code, you can have a hands-free voice app.\n\nDownload package from NPM.\n\n```shell\nnpm i spoken\n```\n\nInclude package on your app page.\n\n```html\n\u003cscript src=\"https://stephenlb.github.io/spoken/spoken.js\"\u003e\u003c/script\u003e\n```\n\nAccess `spoken` global in your app.\n\n```javascript\nspoken.say('Should I turn the hallway light on?').then( speech =\u003e {\n    spoken.listen().then( transcript =\u003e\n        console.log(\"Answer: \" + transcript) )\n} )\n```\n\n### ES6 Modules / Webpack Import Example\n\nIf you are looking to import\n\n```html\n\u003cscript nomodule src=\"./spoken.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"module\"\u003e\n    import spoken from './build/spoken.js';\n    spoken.say('Hello there!');\n\u003c/script\u003e\n```\n\n### Code Playground\n\n\u003e **Playground URL:** https://stephenlb.github.io/spoken/\n\nYou can test the code right now in your Chrome browser.\nClick the playground link above to try it out.\n\n[![Text-to-Speech and Speech-to-Text](https://i.imgur.com/75tQtoZ.png)](https://stephenlb.github.io/spoken/)\n\n### Turn Speech into Text and Text into Speech\n\nCompatible on Android / iOS / Linux / Windows / MacOS.\n\n**Spoken** is a Google Chrome Voice App SDK.\nThis SDK allows you to easily call Voice APIs to turn Text to Speech and Speech to Text.\nThe library has no dependencies.\nThis SDK is only for Google Chrome apps on Mobile and Web.\n\nCompatible with Electron (desktop), Ionic, PhoneGap/Cordova, React, Angular, etc.\nThis works on Mobile Chrome.\n\nCurrently there is support for Google Chrome.\nAnd if you are looking to deploy as a mobile app, this **should work** 👌.\n\n### Text-to-Speech\n\nSynthetic voices are pretty good these days.\nYou can still tell they are robot voices.\n\nTurn text into real-world spoken voice.\nThe voice is synthetic.\nYou can pick from a few different voices too.\n\n```javascript\n// Hello World\nspoken.say('Hello World.');\n\n// Say a quick message as Guy Fieri\nspoken.say( 'Looks like your on a trip to flavor town.', 'Daniel' );\n\n// Speak with Damayanti's voice\nspoken.say( 'I am princess of the Vidarbha Kingdom.', 'Damayanti' );\n```\n\n#### Promises and Async/Await\n\nThis SDK Supports modern async programming.\n\n```javascript\n// Promise\nspoken.say('Hello World.').then( v =\u003e console.log('Done talking.') );\n\n// Async/Await\nawait spoken.say('Hello World.');\nconsole.log('Done talking.');\n```\n\n### Text-to-Speech Voice Selection Library\n\nSynthetic voices are selectable using the `spoken.voices` method.\nThere is a default voice that is included.\nYou may want to pick a different voice.\nThe following examples show you how to select a differnt voice.\n\n```javascript\n// List of voices supported on platform\nconsole.log( await spoken.voices() );\n\n// List of voices with promise callback\nspoken.voices().then( voices =\u003e console.log(voices) );\n```\n\nBy default your language is auto-detected for you\nfrom `navigator.language` attribute.\nYou can override this behavior using the following example.\n\nGet list of **English** voices.\n\n```javascript\n// List of English Speaking Voices\nspoken.recognition.language = navigator.language || 'en-US';\nlet voices = (await spoken.voices()).filter( v =\u003e !v.lang.indexOf('en') );\n\n// Use the First Voice\nspoken.say( 'Welcome to flavor town.', voices[0] );\n```\n\nSample the list of English voices.\n\n```javascript\n// Speak with each English voice to sample your favorites\n(await spoken.voices())\n    .filter( voice =\u003e voice.lang.indexOf('en') == 0 )\n    .map( voice =\u003e voice.name )\n    .forEach( voice =\u003e\n        spoken.say( 'Welcome to flavor town.', voice ).then(\n            speech =\u003e console.log(speech.voice.name)\n        )\n    );\n```\n\n### Speech-to-Text\n\n\u003e Must use HTTPS to access microphone.\n\nYou need an HTTPS (TLS) File Server. To start a local secure file server:\n\n```shell\npython \u003c(curl -L https://goo.gl/LiW3lp)\n```\n\nThen open your browser and point it to your file in\nthe directory you ran the python HTTPS server.\n\n```shell\nopen https://0.0.0.0:4443/index.html\n```\n\n\u003e This is a Simple Python HTTPS Secure Server\n\u003e https://gist.github.com/stephenlb/2e19d98039469b9d0134\n\nWe posted an answer on\n[StackOverflow WebRTC HTTPS](http://stackoverflow.com/a/41969170/524733).\nThis will get you started testing on your laptop.\n\nTurn your spoken words into text using the `listen()` method.\nYou will want to also take advantage of the real-time speech\ndetection using the `spoken.listen.on.partial()` event.\nThis allows you to display the current transcription before\nyour utterance is finished.\n\nFirst you should check to see if the browser has access\nto the Speech-to-Text capability.\n\n```javascript\nconst available = spoken.listen.available();\nif (available) console.log('Hurray voice transcription is available!');\n```\n\nThe following will allow you to capture the full transcription\nof an utterance spoken into your microphone.\nThe results can be used to send to a chatbot API.\n\n```javascript\n// Async/Await\nconsole.log(await spoken.listen());\n\n// or Promise style\nspoken.listen()\n    .then( transcript =\u003e console.log(transcript)     )\n    .catch(     error =\u003e console.warn(error.message) )\n```\n\nThere can only be one concurrent listener.\nYou can catch for this.\n\n```javascript\n// We can only have one concurrent listener.\n// So you can catch if there is an error.\nspoken.listen()\n    .then( transcript =\u003e console.log(transcript)     )\n    .catch(     error =\u003e console.warn(error.message) )\n```\n\nCapture live \"real-time\" transcription as you speak.\n\n```javascript\nspoken.listen.on.partial( ts =\u003e console.log(ts) );\nspoken.listen()\n    .then(     ts =\u003e console.log(\"Partial: \" + ts) )\n    .catch( error =\u003e console.warn(error.message)   )\n```\n\nAdditional voice transcription events.\n\n```javascript\nspoken.listen.on.start( voice =\u003e { console.log('Started Listening') } );\nspoken.listen.on.end(   voice =\u003e { console.log('Ended Listening')   } );\nspoken.listen.on.error( voice =\u003e { console.log('Error Listening')   } );\n```\n\nStop listening.\n\n```javascript\nspoken.listen.stop();\n```\n\n### Continuous Listening Example\n\nWriting a document with your voice or chatting with your friend hands-free\nis possible when you enable `continuous` listening mode.\n\n```javascript\nspoken.listen.on.end(continueCapture);\nspoken.listen.on.error(continueCapture);\n\nstartCapture();\n\nfunction startCapture() { \n    spoken.listen({ continuous : true }).then( transcript =\u003e\n        console.log(\"Captured transcript: \" + transcript)\n    ).catch( e =\u003e true );\n}\n\nasync function continueCapture() {\n    await spoken.delay(300);\n    if (spoken.recognition.continuous) startCapture();\n}\n\nfunction stopCapture() {\n    spoken.recognition.continuous = false;\n    spoken.listen.stop();\n}\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephenlb%2Fspoken","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstephenlb%2Fspoken","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephenlb%2Fspoken/lists"}