{"id":13515470,"url":"https://github.com/cellular/speech-builder","last_synced_at":"2025-04-06T03:33:46.826Z","repository":{"id":92903698,"uuid":"134414423","full_name":"cellular/speech-builder","owner":"cellular","description":" Utility to generate SSML markup for different voice platforms","archived":false,"fork":false,"pushed_at":"2018-06-08T14:26:08.000Z","size":80,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-21T16:21:20.696Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/cellular.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-05-22T12:50:38.000Z","updated_at":"2024-05-16T19:09:41.000Z","dependencies_parsed_at":"2023-10-01T23:07:35.367Z","dependency_job_id":null,"html_url":"https://github.com/cellular/speech-builder","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cellular%2Fspeech-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cellular%2Fspeech-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cellular%2Fspeech-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cellular%2Fspeech-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cellular","download_url":"https://codeload.github.com/cellular/speech-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247430838,"owners_count":20937873,"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-08-01T05:01:11.681Z","updated_at":"2025-04-06T03:33:41.986Z","avatar_url":"https://github.com/cellular.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# speech-builder\n\n[![Build Status](https://travis-ci.org/cellular/speech-builder.svg?branch=master)](https://travis-ci.org/cellular/speech-builder)\n\nUtility to build SSML documents for different voice platforms.\n\n## Motivation / Approach\n\nSince the major voice platforms all support slightly different subsets of SSML, documents built for one platform often cause errors when used somewhere else.\n\nTo address this issue, speech-builder accepts a list of feature flags as configuration option.\n\n## Basic Usage\n\n```js\nconst { ssml } = require('speech-builder');\n\nconst s = ssml().add('Hello').emphasis('world');\n\nconsole.log(s.toString());\n```\n\n```xml\n\u003cspeak\u003eHello\u003cemphasis\u003eworld\u003c/emphasis\u003e\u003c/speak\u003e\n```\n\n## Advanced Options\n\n### Base URI\n\nSSML allows authors to specify URLs as relative paths which get resolved according to the [xml:base](`https://www.w3.org/TR/2009/REC-speech-synthesis-20090303/#S3.1.3) attribute. This is especially useful for audio files which need to be encoded differently for each platform. On platforms that don't support `xml:base` _speech-builder_ omits the attribute and performs the URL resolving itself.\n\n```js\nssml({\n  features: 'alexa',\n  base: 'https://example.com/audio/16k'\n});\n```\n\n### Lexicon\n\nSpeech sythesizers sometimes fail to pronounce words correctly, especially when mixing multiple languages. Using `.phoneme()` helps but can get quite cumbersome to write. As an alternative you can provide a lexicon:\n\n```js\nssml({\n  features: 'alexa',\n  lexicon: {\n    \"Passquote\": \"paskvoːtə\",\n    \"Lloris Hugo\": { \n      ipa: \"lɔʹris yˌgo\", \n      sub: \"Lohrieß Ügo\"\n    }\n  }\n});\n```\n\n### Plain Text Output\n\nThe speech-builder can not only output SSML markup but also a plain text\nrepresentation with `\u003cp\u003e` tags converted into line breaks. This is useful\nfor adding some basic formatting for visual surfaces.\n\n```js\nssml().p('Hello').p('world!').toPlainText();\n```\n\n## API\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n#### Table of Contents\n\n-   [lang](#lang)\n-   [addText](#addtext)\n-   [addToken](#addtoken)\n-   [add](#add)\n-   [sub](#sub)\n-   [phoneme](#phoneme)\n-   [break](#break)\n-   [audio](#audio)\n-   [emphasis](#emphasis)\n-   [p](#p)\n-   [s](#s)\n-   [w](#w)\n-   [effect](#effect)\n-   [sayAs](#sayas)\n-   [prosody](#prosody)\n-   [toString](#tostring)\n-   [toPlainText](#toplaintext)\n-   [replace](#replace)\n\n### lang\n\nAdds an `xml:lang` attribute to the current node.\nIf not supported, this is a no-op.\n\n**Parameters**\n\n-   `lang` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** \n\n### addText\n\nAdds text. Characters with special meaning in XML are properly escaped.\n\n**Parameters**\n\n-   `text` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \\| [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** \n\n### addToken\n\nLike `addText` but prepends a space (unless it's the first token or the\nprevious one alreads ends with whitespace).\n\n**Parameters**\n\n-   `text` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \\| [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** \n\n### add\n\nLike `addToken` but also accepts a function or an array.\n\n**Parameters**\n\n-   `content` **any** \n\n### sub\n\nAdds a `\u003csub\u003e` tag. If substitions are not supported,\nthe alias is added as text instead.\n\n**Parameters**\n\n-   `text` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** \n-   `alias` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** \n\n### phoneme\n\nAdds a `\u003cphoneme\u003e` tag. When an object with notations in\ndifferent alphabets is passed as `ph`, the first one\nthat is supported will be used. For platforms without phoneme\nsupport, the special `sub` alphabet can be used to generate\na `\u003csub\u003e` tag as fallback.\n\n**Parameters**\n\n-   `text` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** \n-   `ph` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)? | {})** \n\n### break\n\nAdds a `\u003cbreak\u003e` tag. If not supported, this is a no-op.\n\n**Parameters**\n\n-   `time` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)? | [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** \n\n### audio\n\nAdds an `\u003caudio\u003e` tag. If not supported, the alt text\nis added as plain text.\n\n**Parameters**\n\n-   `src` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | {src: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), alt: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?})** \n\n### emphasis\n\nAdds an `\u003cemphasis\u003e` tag. If not supported, the text is added as-is.\n\n**Parameters**\n\n-   `content` **any** \n-   `level` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** \n\n### p\n\nAdds a `\u003cp\u003e` tag. If not supported, the text is added as-is.\n\n**Parameters**\n\n-   `content` **any** \n\n### s\n\nAdds an `\u003cs\u003e` tag. If not supported, the text is added as-is.\n\n**Parameters**\n\n-   `content` **any** \n\n### w\n\nAdds a `\u003cw\u003e` tag. If not supported, the text is added as-is.\n\n**Parameters**\n\n-   `role` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** \n-   `content` **any** \n\n### effect\n\nAdds an `\u003c*:effect\u003e` tag. If not supported, the text is added as-is.\nNOTE: The namespace can be configured via the `effect` feature setting.\n\n**Parameters**\n\n-   `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** \n-   `content` **any** \n\n### sayAs\n\nAdds an `\u003csay-as\u003e` tag. If not supported, the text is added as-is.\n\n**Parameters**\n\n-   `interpretAs` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** \n-   `text` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \\| [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** \n-   `format` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** \n-   `detail` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)? | [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number))** \n\n### prosody\n\nAdds a `\u003cprosody\u003e` tag. If not supported, the text is added as-is.\n\n**Parameters**\n\n-   `attrs` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** \n-   `text` **any** \n\n### toString\n\nReturns the serialized SSML document.\n\nReturns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** \n\n### toPlainText\n\nReturns the document without any markup.\nParagraphs are turned into line breaks.\n\nReturns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** \n\n### replace\n\nDuck-type as string to support the Jovo framework.\n\n**Parameters**\n\n-   `pattern` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \\| [RegExp](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp))** \n-   `replacement` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \\| [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function))** \n\n## Adding variations\n\n```js\nconst { ssml } = require('speech-builder');\nconst { random, chance } = require('variation');\n\nssml()\n  .add(random('hello', 'ciao', 'hola', 'salut'))\n  .add(chance(0.5, 'beautiful'))\n  .add('world');\n```\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcellular%2Fspeech-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcellular%2Fspeech-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcellular%2Fspeech-builder/lists"}