kosich / rxjs-tts

RxJS wrapper for Text-to-Speech Web API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


๐Ÿ—ฃ
Web API Text-to-Speech with RxJS

NPM Bundlephobia MIT license


This is a RxJS wrapper around browser native SpeechSynthesis.

It provides handy interface for chaining and aborting TTS.

Try it online

Install

npm i rxjs-tts

Usage

import { speak } from 'rxjs-tts';

speak('Hello!').subscribe();

Chained

import { speak } from 'rxjs-tts';

concat(
    speak('Hello, mom!'),
    speak('How are you?'),
    speak('I miss you.'),
).subscribe();

Advanced usage

import { of, merge, concat, timer } from 'rxjs';
import { map, takeUntil } from 'rxjs/operators';
import { speak, SpeechSynthesisUtteranceConfig } from 'rxjs-tts';

const a: string = 'Hello, mom!';

const b: SpeechSynthesisUtteranceConfig = {
    text: 'How are you?',
    lang: 'en-UK',
    pitch: 1,
    rate: 1,
    volume: 1,
};

const c = new SpeechSynthesisUtterance('I miss you');
c.rate = 1;
c.lang = 'en-US';
c.pitch = 1;
c.rate = 1;
c.volume = 1;

concat(speak(a), speak(b), speak(c)).subscribe((e: SpeechSynthesisEvent) => {
    console.log(e.name);
    console.log(e.type);
});

Enjoy ๐Ÿ™‚

About

RxJS wrapper for Text-to-Speech Web API

License:MIT License


Languages

Language:TypeScript 61.7%Language:JavaScript 38.3%