Socket
Socket
Sign inDemoInstall

ts-ssml-builder

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ts-ssml-builder

## Description Speech Synthesis Markup Language (SSML) is an XML-based markup language for speech synthesis applications.


Version published
Weekly downloads
1
Maintainers
1
Install size
15.1 kB
Created
Weekly downloads
 

Readme

Source

ssml-builder

Description

Speech Synthesis Markup Language (SSML) is an XML-based markup language for speech synthesis applications.

This library supports the creation of SSML.

Install

npm install ts-ssml-builder

Usage

import { SSMLBuilder } from 'ts-ssml-builder';

const builder = new SSMLBuilder();
const ssml = builder
    .paragraph()
        .raw('This is sample')
        .break({ time: '10s' })
        .audio( {src: 'audio.mp4' } )
        .up()
    .up()
    .ssml();
console.log( ssml )
/** 
 * Output: String
 * <speak><p >This is sample<break time="10s" /><audio src="audio.mp4"></audio></p></speak>
*/

API

interface ISsmlBuilder {
    ssml(): string;
    raw( value: string, useEscape?: boolean ): Builder;
    sayAs( option: interfaces.ISayAs ): Builder;
    break( option?: Partial<interfaces.IBreak> ): Builder;
    sub( option: interfaces.ISub ): Builder;
    audio( option: interfaces.IAudio ): Builder; // Wrap tag
    sentence(): Builder; // Wrap tag
    paragraph(): Builder; // Wrap tag
    prosody( option: interfaces.IProsody ): Builder;
    emphasis( option?: interfaces.IEmphasis ): Builder; // Wrap tag
    up(): Builder;
};

export class Builder implements ISsmlBuilder { /** */}

Wrap tag( sentence, paragraph... ) needs to explicitly call up() when closing a tag.

NameWrap tag?Description
rawNoYou can add text and insert custom tags. useEscape is default true. 
sayAsNoInsert the say-as tag.
breakNoInsert the break tag.
subNoInsert the sub tag.
audioYesInsert the audio tag.
sentenceYesInsert the s tag.
paragraphYesInsert the p tag.
prosodyNoInsert the prosody tag.
emphasisYesInsert the emphasis tag.

API Params

The audio and prosody can be set to any attribute.

type InterpretAs = 'characters' | 'spell-out' | 'cardinal' | 'number' | 'address'
    | 'ordinal' | 'digits' | 'fraction' | 'unit' | 'date' | 'time' | 'telephone' 
    | 'interjection' | 'expletive'
interface ISayAs {
    interpretAs: InterpretAs;
    word: string;
    format?: string;
    detail?: string;
};

type BreakStrength = 'none' | 'x-weak' | 'weak' | 'medium' | 'strong' | 'x-strong'

interface IBreak {
    strength: BreakStrength;
    time: string;
};

interface ISub {
    alias: string;
    word: string;
};

interface IAudio {
    src: string;
    [ key: string ] : string;
};
interface IProsody {
    word: string;
    [ key: string ] : string;
};
export type EmphasisLevel = 'strong' | 'moderate' | 'none' | 'reduced'
export interface IEmphasis {
    level: EmphasisLevel;
};

Escape

Applies to all word values of the above API parameters and when useEscape of API:raw is true.

Therefore, if you use custom elements in raw, useEscape should be set to false.

/* Escape processing */
escapedLines = escapedLines.replace(/&/g, '&amp;');
escapedLines = escapedLines.replace(/"/g, '&quot;');
escapedLines = escapedLines.replace(/</g, '&lt;');
escapedLines = escapedLines.replace(/>/g, '&gt;');

Feature

  • Corresponding to commonly used tag.
  • Support for additional Google Text-to-Speech features.
  • Support for additional Amazon Alexa features.

Licence

MIT

FAQs

Last updated on 16 Mar 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc