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
27
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 - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1-dev.754cf30

dist/plugin.cjs.js

65

dist/esm/definitions.d.ts

@@ -1,2 +0,2 @@

declare module "@capacitor/core" {
declare module '@capacitor/core' {
interface PluginRegistry {

@@ -7,23 +7,15 @@ TextToSpeech: TextToSpeechPlugin;

export interface TextToSpeechPlugin {
speak(options: TTSOptions): Promise<void>;
speak(options: TTSSpeakOptions): Promise<void>;
stop(): Promise<void>;
getSupportedLanguages(): Promise<{
languages: any;
}>;
getSupportedVoices(): Promise<{
voices: SpeechSynthesisVoice[];
}>;
getSupportedLanguages(): Promise<TTSLanguages>;
getSupportedVoices(): Promise<TTSVoices>;
openInstall(): Promise<void>;
setPitchRate(options: {
pitchRate: number;
}): Promise<void>;
setSpeechRate(options: {
speechRate: number;
}): Promise<void>;
setPitch(options: TTSPitchOptions): Promise<void>;
setRate(options: TTSRateOptions): Promise<void>;
}
export interface TTSOptions {
export interface TTSSpeakOptions {
text: string;
locale?: string;
rate?: number;
pitch?: number;
speechRate?: number;
pitchRate?: number;
volume?: number;

@@ -33,8 +25,41 @@ voice?: number;

}
export interface TTSPitchOptions {
pitch: number;
}
export interface TTSRateOptions {
rate: number;
}
export interface TTSVoices {
voices: SpeechSynthesisVoice[];
}
export interface TTSLanguages {
languages: any;
}
/**
* The SpeechSynthesisVoice interface represents a voice that the system supports.
*/
export interface SpeechSynthesisVoice {
voiceURI: string;
name: string;
/**
* Specifies whether the voice is the default voice for the current app (`true`) or not (`false`).
*/
default: boolean;
/**
* BCP 47 language tag indicating the language of the voice.
* Example: `en-US`
*/
lang: string;
/**
* Specifies whether the voice is supplied by a local (`true`) or remote (`false`) speech synthesizer service.
*/
localService: boolean;
default: boolean;
/**
* Human-readable name that represents the voice.
* Example: `Microsoft Zira Desktop - English (United States)`
*/
name: string;
/**
* Type 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`
*/
voiceURI: string;
}
export * from './definitions';
export * from './web';
export * from './definitions';
export * from './web';
//# sourceMappingURL=index.js.map

@@ -1,26 +0,20 @@

import { WebPlugin } from "@capacitor/core";
import { TextToSpeechPlugin, TTSOptions, SpeechSynthesisVoice } from "./definitions";
import { WebPlugin } from '@capacitor/core';
import { TextToSpeechPlugin, TTSSpeakOptions, TTSPitchOptions, TTSRateOptions, TTSVoices, TTSLanguages } from './definitions';
export declare class TextToSpeechWeb extends WebPlugin implements TextToSpeechPlugin {
private speechSynthesizer;
private activeUtterance;
private notSupportedMessage;
private supportedVoices;
private speechSynthesis;
private currentlyActive;
constructor();
speak(options: TTSOptions): Promise<void>;
speak(options: TTSSpeakOptions): Promise<void>;
stop(): Promise<void>;
getSupportedLanguages(): Promise<{
languages: any;
}>;
getSupportedVoices(): Promise<{
voices: SpeechSynthesisVoice[];
}>;
getSupportedLanguages(): Promise<TTSLanguages>;
getSupportedVoices(): Promise<TTSVoices>;
openInstall(): Promise<void>;
setPitchRate(_options: {
pitchRate: number;
}): Promise<void>;
setSpeechRate(_options: {
speechRate: number;
}): Promise<void>;
setPitch(_options: TTSPitchOptions): Promise<void>;
setRate(_options: TTSRateOptions): Promise<void>;
private throwUnsupportedError;
private getSpeechSynthesis;
private getSpeechSynthesisVoices;
private createSpeechSynthesisUtterance;
}
declare const TextToSpeech: TextToSpeechWeb;
export { TextToSpeech };

@@ -1,100 +0,124 @@

import { WebPlugin } from "@capacitor/core";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { WebPlugin } from '@capacitor/core';
export class TextToSpeechWeb extends WebPlugin {
constructor() {
super({
name: "TextToSpeech",
platforms: ["web"],
name: 'TextToSpeech',
platforms: ['web'],
});
this.notSupportedMessage = "Speech Synthesizer is not yet initialized or supported.";
this.supportedVoices = [];
if (!this.speechSynthesizer && window && window.speechSynthesis) {
this.speechSynthesizer = window.speechSynthesis;
}
this.currentlyActive = false;
this.speechSynthesis = this.getSpeechSynthesis();
}
speak(options) {
return new Promise((resolve, reject) => {
if (!this.speechSynthesizer) {
reject(this.notSupportedMessage);
return;
return __awaiter(this, void 0, void 0, function* () {
const speechSynthesis = this.speechSynthesis;
if (!speechSynthesis) {
this.throwUnsupportedError();
}
if (!options) {
reject("No options were provided.");
if (this.currentlyActive) {
return;
}
if (!options.text) {
reject("Text option was not provided");
return;
}
const { text, locale, rate, volume, voice, pitch } = options;
if (!this.activeUtterance) {
this.activeUtterance = new SpeechSynthesisUtterance();
this.supportedVoices = window.speechSynthesis.getVoices();
this.activeUtterance.voice = this.supportedVoices[voice];
this.activeUtterance.rate = rate >= 0.1 && rate <= 10 ? rate : 1;
this.activeUtterance.volume = volume >= 0 && volume <= 1 ? volume : 1;
this.activeUtterance.text = text;
this.activeUtterance.lang = locale;
this.activeUtterance.pitch = pitch >= 0 && pitch <= 2 ? pitch : 2;
if (voice) {
this.activeUtterance.voice = voice;
}
this.activeUtterance.onend = (ev) => {
resolve(ev);
this.activeUtterance = undefined;
this.currentlyActive = true;
const utterance = yield this.createSpeechSynthesisUtterance(options);
return new Promise((resolve, reject) => {
utterance.onend = () => {
this.currentlyActive = false;
resolve();
};
this.activeUtterance.onerror = (ev) => {
reject(ev);
this.activeUtterance = undefined;
utterance.onerror = (event) => {
this.currentlyActive = false;
reject(event);
};
this.speechSynthesizer.speak(this.activeUtterance);
}
speechSynthesis.speak(utterance);
});
});
}
stop() {
return new Promise((resolve, reject) => {
if (!this.speechSynthesizer) {
reject(this.notSupportedMessage);
return;
return __awaiter(this, void 0, void 0, function* () {
if (!this.speechSynthesis) {
this.throwUnsupportedError();
}
this.speechSynthesizer.cancel();
resolve();
this.speechSynthesis.cancel();
});
}
getSupportedLanguages() {
return new Promise((resolve, reject) => {
if (!this.speechSynthesizer) {
reject(this.notSupportedMessage);
return;
}
resolve();
return __awaiter(this, void 0, void 0, function* () {
const voices = this.getSpeechSynthesisVoices();
const languages = voices.map(voice => voice.lang);
return { languages };
});
}
getSupportedVoices() {
return new Promise((resolve, reject) => {
if (!this.speechSynthesizer) {
reject(this.notSupportedMessage);
return;
}
this.supportedVoices = window.speechSynthesis.getVoices();
resolve({
voices: this.supportedVoices,
});
return __awaiter(this, void 0, void 0, function* () {
const voices = this.getSpeechSynthesisVoices();
return { voices };
});
}
openInstall() {
throw new Error("Method not implemented.");
return __awaiter(this, void 0, void 0, function* () {
throw new Error('Not implemented on web.');
});
}
setPitchRate(_options) {
// Pitch rate cannot be set while engine is active
throw new Error("Method not implemented.");
setPitch(_options) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error('Not implemented on web.');
});
}
setSpeechRate(_options) {
// Speech rate cannot be set while engine is active
throw new Error("Method not implemented.");
setRate(_options) {
return __awaiter(this, void 0, void 0, function* () {
throw new Error('Not implemented on web.');
});
}
throwUnsupportedError() {
throw new Error('Not supported on this device.');
}
getSpeechSynthesis() {
if ('speechSynthesis' in window) {
return window.speechSynthesis;
}
return null;
}
getSpeechSynthesisVoices() {
if (!this.speechSynthesis) {
this.throwUnsupportedError();
}
return this.speechSynthesis.getVoices();
}
createSpeechSynthesisUtterance(options) {
return __awaiter(this, void 0, void 0, function* () {
const utterance = new SpeechSynthesisUtterance();
const voices = this.getSpeechSynthesisVoices();
const { text, locale, speechRate, volume, voice, pitchRate } = options;
if (voice) {
utterance.voice = voices[voice];
}
if (volume) {
utterance.volume = volume >= 0 && volume <= 1 ? volume : 1;
}
if (speechRate) {
utterance.rate = speechRate >= 0.1 && speechRate <= 10 ? speechRate : 1;
}
if (pitchRate) {
utterance.pitch = pitchRate >= 0 && pitchRate <= 2 ? pitchRate : 2;
}
if (locale) {
utterance.lang = locale;
}
utterance.text = text;
return utterance;
});
}
}
const TextToSpeech = new TextToSpeechWeb();
export { TextToSpeech };
import { registerWebPlugin } from "@capacitor/core";
import { registerWebPlugin } from '@capacitor/core';
registerWebPlugin(TextToSpeech);
//# sourceMappingURL=web.js.map
{
"name": "@capacitor-community/text-to-speech",
"version": "0.2.0",
"description": "A native plugin for text to speech engine",
"main": "dist/esm/index.js",
"version": "0.2.1-dev.754cf30",
"description": "Capacitor plugin for synthesizing speech from text.",
"main": "dist/plugin.js",
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"scripts": {
"build": "npm run clean && tsc",
"lint": "npm run prettier -- --check && npm run swiftlint -- lint",
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
"swiftlint": "node-swiftlint",
"build": "npm run clean && tsc && rollup -c rollup.config.js",
"clean": "rimraf ./dist",
"watch": "tsc --watch",
"prepublishOnly": "npm run build",
"npm-publish": "np"
"release": "standard-version"
},
"author": "Priyank Patel <priyank.patel@stackspace.ca>",
"contributors": [
"Priyank Patel <priyank.patel@stackspace.ca>",
"Robin Genz <mail@robingenz.dev>"
],
"license": "MIT",

@@ -20,21 +27,20 @@ "dependencies": {

"devDependencies": {
"@capacitor/android": "latest",
"@capacitor/ios": "latest",
"husky": "^4.2.5",
"np": "^6.2.4",
"prettier": "^2.0.5",
"prettier-plugin-java": "^0.8.0",
"pretty-quick": "^2.0.1",
"rimraf": "^3.0.2",
"typescript": "^3.9.5"
"@capacitor/android": "2.4.7",
"@capacitor/core": "2.4.7",
"@capacitor/ios": "2.4.7",
"@ionic/prettier-config": "1.0.1",
"@ionic/swiftlint-config": "1.1.2",
"prettier": "2.0.5",
"prettier-plugin-java": "0.8.3",
"rimraf": "3.0.2",
"rollup": "2.21.0",
"standard-version": "9.1.0",
"swiftlint": "1.0.1",
"typescript": "3.9.5"
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
},
"files": [
"android/src/main/",
"android/build.gradle",
"dist/",
"ios/",
"android/",
"ios/Plugin/",
"CapacitorCommunityTextToSpeech.podspec"

@@ -55,3 +61,4 @@ ],

},
"homepage": "https://github.com/capacitor-community/text-to-speech",
"prettier": "@ionic/prettier-config",
"swiftlint": "@ionic/swiftlint-config",
"repository": {

@@ -58,0 +65,0 @@ "type": "git",

@@ -5,8 +5,8 @@ <p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p>

<p align="center">
Capacitor community plugin for native <a href="https://firebase.google.com/docs/crashlytics">Firebase Crashlytics</a>.
Capacitor community plugin for synthesizing speech from text.
</p>
<p align="center">
<img src="https://img.shields.io/maintenance/yes/2020?style=flat-square" />
<a href="https://github.com/capacitor-community/text-to-speech/actions?query=workflow%3A%22Test+and+Build+Plugin%22"><img src="https://img.shields.io/github/workflow/status/capacitor-community/text-to-speech/Test%20and%20Build%20Plugin?style=flat-square" /></a>
<img src="https://img.shields.io/maintenance/yes/2021?style=flat-square" />
<a href="https://github.com/capacitor-community/text-to-speech/actions?query=workflow%3A%22CI%22"><img src="https://img.shields.io/github/workflow/status/capacitor-community/text-to-speech/CI/master?style=flat-square" /></a>
<a href="https://www.npmjs.com/package/@capacitor-community/text-to-speech"><img src="https://img.shields.io/npm/l/@capacitor-community/text-to-speech?style=flat-square" /></a>

@@ -17,3 +17,3 @@ <br>

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-3-orange?style=flat-square" /></a>
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-1-orange?style=flat-square" /></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->

@@ -24,31 +24,16 @@ </p>

| Maintainer | GitHub | Social |
| ------------- | ------------------------------------------- | ------------------------------------------------ |
| Priyank Patel | [priyankpat](https://github.com/priyankpat) | [@priyankpat\_](https://twitter.com/priyankpat_) |
| Maintainer | GitHub | Social |
| ---------- | ----------------------------------------- | --------------------------------------------- |
| Robin Genz | [robingenz](https://github.com/robingenz) | [@robin_genz](https://twitter.com/robin_genz) |
Mainteinance Status: Actively Maintained
## Installation
To use npm
```bash
npm install @capacitor/text-to-speech
```
To use yarn
```bash
yarn add @capacitor/text-to-speech
```
Sync native files
```bash
npm install @capacitor-community/text-to-speech
npx cap sync
```
On iOS, no further steps are needed.
On **iOS**, no further steps are needed.
On Android, register the plugin in your main activity:
On **Android**, register the plugin in your main activity:

@@ -99,5 +84,5 @@ ```java

// Must import the package once to make sure the web support initializes
import "@capacitor-community/text-to-speech";
import '@capacitor-community/text-to-speech';
import { Plugins } from "@capacitor/core";
import { Plugins } from '@capacitor/core';

@@ -118,4 +103,4 @@ const { TextToSpeech } = Plugins;

TextToSpeech.speak({
text: "This is a sample text.",
locale: "en_US",
text: 'This is a sample text.',
locale: 'en_US',
speechRate: 1.0,

@@ -125,3 +110,3 @@ pitchRate: 1,

voice: 10,
category: "ambient",
category: 'ambient',
});

@@ -181,1 +166,9 @@

```
## Changelog
See [CHANGELOG.md](https://github.com/capacitor-community/text-to-speech/blob/master/CHANGELOG.md).
## License
See [LICENSE](https://github.com/capacitor-community/text-to-speech/blob/master/LICENSE).

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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