Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@capacitor-community/text-to-speech

Package Overview
Dependencies
Maintainers
29
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@capacitor-community/text-to-speech

Capacitor plugin for synthesizing speech from text.

  • 0.2.3-dev.6ffcfb9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.4K
decreased by-14.58%
Maintainers
29
Weekly downloads
 
Created
Source


Text to Speech

@capacitor-community/text-to-speech

Capacitor community plugin for synthesizing speech from text.


Maintainers

MaintainerGitHubSocial
Robin Genzrobingenz@robin_genz

Installation

Capacitor 3.x

npm install @capacitor-community/text-to-speech
npx cap sync

Capacitor 2.x

npm install @capacitor-community/text-to-speech@0.2.3
npx cap sync

On iOS, no further steps are needed.

On Android, register the plugin in your main activity:

import com.getcapacitor.community.tts.TextToSpeech;

public class MainActivity extends BridgeActivity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initializes the Bridge
    this.init(
        savedInstanceState,
        new ArrayList<Class<? extends Plugin>>() {
          {
            // Additional plugins you've installed go here
            // Ex: add(TotallyAwesomePlugin.class);
            add(TextToSpeech.class);
          }
        }
      );
  }
}

Configuration

No configuration required for this plugin.

Usage

import { TextToSpeech } from '@capacitor-community/text-to-speech';

const speak = async () => {
  await TextToSpeech.speak({
    text: 'This is a sample text.',
    locale: 'en_US',
    speechRate: 1.0,
    pitchRate: 1.0,
    volume: 1.0,
    category: 'ambient',
  });
};

const stop = async () => {
  await TextToSpeech.stop();
};

const getSupportedLanguages = async () => {
  const languages = await TextToSpeech.getSupportedLanguages();
};

const getSupportedVoices = async () => {
  const voices = await TextToSpeech.getSupportedVoices();
};

const setPitchRate = async () => {
  await TextToSpeech.setPitchRate({
    pitchRate: 1.5,
  });
};

const setSpeechRate = async () => {
  await TextToSpeech.setSpeechRate({
    speechRate: 0.5,
  });
};

API

speak(...)

speak(options: TTSOptions) => Promise<void>

Starts the TTS engine and plays the desired text.

ParamType
optionsTTSOptions

stop()

stop() => Promise<void>

Stops the TTS engine.


getSupportedLanguages()

getSupportedLanguages() => Promise<{ languages: string[]; }>

Returns a list of supported languages.

Returns: Promise<{ languages: string[]; }>


getSupportedVoices()

getSupportedVoices() => Promise<{ voices: SpeechSynthesisVoice[]; }>

Returns a list of supported voices.

Returns: Promise<{ voices: SpeechSynthesisVoice[]; }>


openInstall()

openInstall() => Promise<void>

Verifies proper installation and availability of resource files on the system.


setPitchRate(...)

setPitchRate(options: { pitchRate: number; }) => Promise<void>

Changes the pitch rate while the text is being played.

Only available for Android.

ParamType
options{ pitchRate: number; }

setSpeechRate(...)

setSpeechRate(options: { speechRate: number; }) => Promise<void>

Changes the speech rate while the text is being played.

Only available for Android.

ParamType
options{ speechRate: number; }

Interfaces

TTSOptions
PropTypeDescription
textstringText to be spoken.
localestringLanguage spoken in. Possible languages can be queried using getSupportedLanguages. Default: en-US
speechRatenumberThe speech rate. Default: 1.0
pitchRatenumberThe pitch rate. Default: 1.0
volumenumberThe volume. Default: 1.0
voicenumberThe index of the selected voice. Possible voices can be queried using getSupportedVoices. Only available for Web.
categorystringSelect the iOS Audio session category. Possible values: ambient and playback Use playback to play audio even when the app is in the background. Only available for iOS. Default: ambient
SpeechSynthesisVoice

The SpeechSynthesisVoice interface represents a voice that the system supports.

PropTypeDescription
defaultbooleanSpecifies whether the voice is the default voice for the current app (true) or not (false).
langstringBCP 47 language tag indicating the language of the voice. Example: en-US
localServicebooleanSpecifies whether the voice is supplied by a local (true) or remote (false) speech synthesizer service.
namestringHuman-readable name that represents the voice. Example: Microsoft Zira Desktop - English (United States)
voiceURIstringType of URI and location of the speech synthesis service for this voice. Example: urn:moz-tts:sapi:Microsoft Zira Desktop - English (United States)?en-US

Changelog

See CHANGELOG.md.

License

See LICENSE.

Keywords

FAQs

Package last updated on 13 Mar 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc