Skip to content

ZejusJS/easy-tts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easy-tts

This package is meant to lighten the work around TTS in browsers. It's compatible for every browser because it calls Google Translate API as backup speech.

🟧 Warning The package works, but expect further updates with API changes.

Installation

npm i easy-tts

Usage

Basic

import { speak, listWords } from "easy-tts"

await speak({
  lng: "en",
  text: "Hey, hear my beautiful voice!",
  voiceName: listWords("EN").filteredVoiceNames[0],
  volume: 75,
});

Advenced

import { speak, GoogleVoiceName } from "easy-tts"

await speak({
  lng: "en",
  text: "Hey, hear my beautiful voice!",
  voiceName: GoogleVoiceName, // sets the voice of Google Translate
  volume: 75,
  stopCurrentSpeech: false,
  pitch: 1.5,
  rate: 2, // 2x speed of voice
  forceGoogleMinRate: 0.5,
  forceGoogleMaxRate: 5
});

Google TTS

import { speak, listWords, GoogleVoiceName } from "easy-tts"

await speak({
  lng: "en",
  text: "Hey, hear my beautiful voice!",
  voiceName: GoogleVoiceName,
  volume: 75,
});

SpeechSynthesis Compatibility

Check whether or not the user's browser is capable of using built in TTS.

Speech Synthesis API

import { checkSpeechSynthesisCompatibility } from "easy-tts"

checkSpeechSynthesisCompatibility()
checkSpeechSynthesisCompatibility("en")

Pause, resume and cancel speech

import { cancelSpeech, resumeSpeech, pauseSpeech, speak } from "easy-tts";

speak({...})
pauseSpeech()
resumeSpeech()

speak({...})
cancelSpeech()

Examples

TODOS

  • Appending hidden audio element
  • Provide an example of user's choice of TTS voice
  • Fn stop
  • Fn pause
  • Fn resume
  • Fn isSpeaking
  • Pitch option
  • Async

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published