@capacitor-community/text-to-speech
Advanced tools
Comparing version 0.2.2 to 0.2.3-dev.6ffcfb9
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.2.3](https://github.com/capacitor-community/text-to-speech/compare/v0.2.2...v0.2.3) (2021-03-12) | ||
### Bug Fixes | ||
* **ios:** pod failed to validate ([#46](https://github.com/capacitor-community/text-to-speech/issues/46)) ([6a83100](https://github.com/capacitor-community/text-to-speech/commit/6a831003d3c29f9fa6a46dc27e20267246b3ec1a)) | ||
### [0.2.2](https://github.com/capacitor-community/text-to-speech/compare/v0.2.1...v0.2.2) (2021-03-11) | ||
@@ -7,0 +14,0 @@ |
@@ -1,19 +0,39 @@ | ||
declare module '@capacitor/core' { | ||
interface PluginRegistry { | ||
TextToSpeech: TextToSpeechPlugin; | ||
} | ||
} | ||
export interface TextToSpeechPlugin { | ||
/** | ||
* Starts the TTS engine and plays the desired text. | ||
*/ | ||
speak(options: TTSOptions): Promise<void>; | ||
/** | ||
* Stops the TTS engine. | ||
*/ | ||
stop(): Promise<void>; | ||
/** | ||
* Returns a list of supported languages. | ||
*/ | ||
getSupportedLanguages(): Promise<{ | ||
languages: string[]; | ||
}>; | ||
/** | ||
* Returns a list of supported voices. | ||
*/ | ||
getSupportedVoices(): Promise<{ | ||
voices: SpeechSynthesisVoice[]; | ||
}>; | ||
/** | ||
* Verifies proper installation and availability of resource files on the system. | ||
*/ | ||
openInstall(): Promise<void>; | ||
/** | ||
* Changes the pitch rate while the text is being played. | ||
* | ||
* Only available for Android. | ||
*/ | ||
setPitchRate(options: { | ||
pitchRate: number; | ||
}): Promise<void>; | ||
/** | ||
* Changes the speech rate while the text is being played. | ||
* | ||
* Only available for Android. | ||
*/ | ||
setSpeechRate(options: { | ||
@@ -24,8 +44,47 @@ speechRate: number; | ||
export interface TTSOptions { | ||
/** | ||
* Text to be spoken. | ||
*/ | ||
text: string; | ||
/** | ||
* Language spoken in. | ||
* Possible languages can be queried using `getSupportedLanguages`. | ||
* | ||
* Default: `en-US` | ||
*/ | ||
locale?: string; | ||
/** | ||
* The speech rate. | ||
* | ||
* Default: `1.0` | ||
*/ | ||
speechRate?: number; | ||
/** | ||
* The pitch rate. | ||
* | ||
* Default: `1.0` | ||
*/ | ||
pitchRate?: number; | ||
/** | ||
* The volume. | ||
* | ||
* Default: `1.0` | ||
*/ | ||
volume?: number; | ||
/** | ||
* The index of the selected voice. | ||
* Possible voices can be queried using `getSupportedVoices`. | ||
* | ||
* Only available for Web. | ||
*/ | ||
voice?: number; | ||
/** | ||
* Select 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` | ||
*/ | ||
category?: string; | ||
@@ -32,0 +91,0 @@ } |
@@ -0,1 +1,2 @@ | ||
export {}; | ||
//# sourceMappingURL=definitions.js.map |
@@ -0,2 +1,4 @@ | ||
import type { TextToSpeechPlugin } from './definitions'; | ||
declare const TextToSpeech: TextToSpeechPlugin; | ||
export * from './definitions'; | ||
export * from './web'; | ||
export { TextToSpeech }; |
@@ -0,3 +1,7 @@ | ||
import { registerPlugin } from '@capacitor/core'; | ||
const TextToSpeech = registerPlugin('TextToSpeech', { | ||
web: () => import('./web').then(m => new m.TextToSpeechWeb()), | ||
}); | ||
export * from './definitions'; | ||
export * from './web'; | ||
export { TextToSpeech }; | ||
//# sourceMappingURL=index.js.map |
import { WebPlugin } from '@capacitor/core'; | ||
import { TextToSpeechPlugin, SpeechSynthesisVoice, TTSOptions } from './definitions'; | ||
import type { TextToSpeechPlugin, TTSOptions } from './definitions'; | ||
export declare class TextToSpeechWeb extends WebPlugin implements TextToSpeechPlugin { | ||
private speechSynthesis; | ||
private supportedVoices; | ||
constructor(); | ||
@@ -26,3 +27,1 @@ speak(options: TTSOptions): Promise<void>; | ||
} | ||
declare const TextToSpeech: TextToSpeechWeb; | ||
export { TextToSpeech }; |
@@ -1,10 +0,1 @@ | ||
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'; | ||
@@ -22,57 +13,43 @@ export class TextToSpeechWeb extends WebPlugin { | ||
} | ||
speak(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.speechSynthesis) { | ||
this.throwUnsupportedError(); | ||
} | ||
yield this.stop(); | ||
const speechSynthesis = this.speechSynthesis; | ||
const utterance = this.createSpeechSynthesisUtterance(options); | ||
return new Promise((resolve, reject) => { | ||
utterance.onend = () => { | ||
resolve(); | ||
}; | ||
utterance.onerror = (event) => { | ||
reject(event); | ||
}; | ||
speechSynthesis.speak(utterance); | ||
}); | ||
async speak(options) { | ||
if (!this.speechSynthesis) { | ||
this.throwUnsupportedError(); | ||
} | ||
await this.stop(); | ||
const speechSynthesis = this.speechSynthesis; | ||
const utterance = this.createSpeechSynthesisUtterance(options); | ||
return new Promise((resolve, reject) => { | ||
utterance.onend = () => { | ||
resolve(); | ||
}; | ||
utterance.onerror = (event) => { | ||
reject(event); | ||
}; | ||
speechSynthesis.speak(utterance); | ||
}); | ||
} | ||
stop() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.speechSynthesis) { | ||
this.throwUnsupportedError(); | ||
} | ||
this.speechSynthesis.cancel(); | ||
}); | ||
async stop() { | ||
if (!this.speechSynthesis) { | ||
this.throwUnsupportedError(); | ||
} | ||
this.speechSynthesis.cancel(); | ||
} | ||
getSupportedLanguages() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const voices = this.getSpeechSynthesisVoices(); | ||
const languages = voices.map(voice => voice.lang); | ||
const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i); | ||
return { languages: filteredLanguages }; | ||
}); | ||
async getSupportedLanguages() { | ||
const voices = this.getSpeechSynthesisVoices(); | ||
const languages = voices.map(voice => voice.lang); | ||
const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i); | ||
return { languages: filteredLanguages }; | ||
} | ||
getSupportedVoices() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const voices = this.getSpeechSynthesisVoices(); | ||
return { voices }; | ||
}); | ||
async getSupportedVoices() { | ||
const voices = this.getSpeechSynthesisVoices(); | ||
return { voices }; | ||
} | ||
openInstall() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.throwUnimplementedError(); | ||
}); | ||
async openInstall() { | ||
this.throwUnimplementedError(); | ||
} | ||
setPitchRate(_options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.throwUnimplementedError(); | ||
}); | ||
async setPitchRate(_options) { | ||
this.throwUnimplementedError(); | ||
} | ||
setSpeechRate(_options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.throwUnimplementedError(); | ||
}); | ||
async setSpeechRate(_options) { | ||
this.throwUnimplementedError(); | ||
} | ||
@@ -105,15 +82,14 @@ createSpeechSynthesisUtterance(options) { | ||
} | ||
return this.speechSynthesis.getVoices(); | ||
if (!this.supportedVoices || this.supportedVoices.length < 1) { | ||
this.supportedVoices = this.speechSynthesis.getVoices(); | ||
} | ||
return this.supportedVoices; | ||
} | ||
throwUnsupportedError() { | ||
throw new Error('Not supported on this device.'); | ||
throw this.unavailable('SpeechSynthesis API not available in this browser.'); | ||
} | ||
throwUnimplementedError() { | ||
throw new Error('Not implemented on web.'); | ||
throw this.unimplemented('Not implemented on web.'); | ||
} | ||
} | ||
const TextToSpeech = new TextToSpeechWeb(); | ||
export { TextToSpeech }; | ||
import { registerWebPlugin } from '@capacitor/core'; | ||
registerWebPlugin(TextToSpeech); | ||
//# sourceMappingURL=web.js.map |
@@ -7,11 +7,6 @@ 'use strict'; | ||
var __awaiter = (undefined && undefined.__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()); | ||
}); | ||
}; | ||
const TextToSpeech = core.registerPlugin('TextToSpeech', { | ||
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.TextToSpeechWeb()), | ||
}); | ||
class TextToSpeechWeb extends core.WebPlugin { | ||
@@ -28,57 +23,43 @@ constructor() { | ||
} | ||
speak(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.speechSynthesis) { | ||
this.throwUnsupportedError(); | ||
} | ||
yield this.stop(); | ||
const speechSynthesis = this.speechSynthesis; | ||
const utterance = this.createSpeechSynthesisUtterance(options); | ||
return new Promise((resolve, reject) => { | ||
utterance.onend = () => { | ||
resolve(); | ||
}; | ||
utterance.onerror = (event) => { | ||
reject(event); | ||
}; | ||
speechSynthesis.speak(utterance); | ||
}); | ||
async speak(options) { | ||
if (!this.speechSynthesis) { | ||
this.throwUnsupportedError(); | ||
} | ||
await this.stop(); | ||
const speechSynthesis = this.speechSynthesis; | ||
const utterance = this.createSpeechSynthesisUtterance(options); | ||
return new Promise((resolve, reject) => { | ||
utterance.onend = () => { | ||
resolve(); | ||
}; | ||
utterance.onerror = (event) => { | ||
reject(event); | ||
}; | ||
speechSynthesis.speak(utterance); | ||
}); | ||
} | ||
stop() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.speechSynthesis) { | ||
this.throwUnsupportedError(); | ||
} | ||
this.speechSynthesis.cancel(); | ||
}); | ||
async stop() { | ||
if (!this.speechSynthesis) { | ||
this.throwUnsupportedError(); | ||
} | ||
this.speechSynthesis.cancel(); | ||
} | ||
getSupportedLanguages() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const voices = this.getSpeechSynthesisVoices(); | ||
const languages = voices.map(voice => voice.lang); | ||
const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i); | ||
return { languages: filteredLanguages }; | ||
}); | ||
async getSupportedLanguages() { | ||
const voices = this.getSpeechSynthesisVoices(); | ||
const languages = voices.map(voice => voice.lang); | ||
const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i); | ||
return { languages: filteredLanguages }; | ||
} | ||
getSupportedVoices() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const voices = this.getSpeechSynthesisVoices(); | ||
return { voices }; | ||
}); | ||
async getSupportedVoices() { | ||
const voices = this.getSpeechSynthesisVoices(); | ||
return { voices }; | ||
} | ||
openInstall() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.throwUnimplementedError(); | ||
}); | ||
async openInstall() { | ||
this.throwUnimplementedError(); | ||
} | ||
setPitchRate(_options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.throwUnimplementedError(); | ||
}); | ||
async setPitchRate(_options) { | ||
this.throwUnimplementedError(); | ||
} | ||
setSpeechRate(_options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.throwUnimplementedError(); | ||
}); | ||
async setSpeechRate(_options) { | ||
this.throwUnimplementedError(); | ||
} | ||
@@ -111,16 +92,21 @@ createSpeechSynthesisUtterance(options) { | ||
} | ||
return this.speechSynthesis.getVoices(); | ||
if (!this.supportedVoices || this.supportedVoices.length < 1) { | ||
this.supportedVoices = this.speechSynthesis.getVoices(); | ||
} | ||
return this.supportedVoices; | ||
} | ||
throwUnsupportedError() { | ||
throw new Error('Not supported on this device.'); | ||
throw this.unavailable('SpeechSynthesis API not available in this browser.'); | ||
} | ||
throwUnimplementedError() { | ||
throw new Error('Not implemented on web.'); | ||
throw this.unimplemented('Not implemented on web.'); | ||
} | ||
} | ||
const TextToSpeech = new TextToSpeechWeb(); | ||
core.registerWebPlugin(TextToSpeech); | ||
var web = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
TextToSpeechWeb: TextToSpeechWeb | ||
}); | ||
exports.TextToSpeech = TextToSpeech; | ||
exports.TextToSpeechWeb = TextToSpeechWeb; | ||
//# sourceMappingURL=plugin.cjs.js.map |
var capacitorTextToSpeech = (function (exports, core) { | ||
'use strict'; | ||
var __awaiter = (undefined && undefined.__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()); | ||
}); | ||
}; | ||
const TextToSpeech = core.registerPlugin('TextToSpeech', { | ||
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.TextToSpeechWeb()), | ||
}); | ||
class TextToSpeechWeb extends core.WebPlugin { | ||
@@ -24,57 +19,43 @@ constructor() { | ||
} | ||
speak(options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.speechSynthesis) { | ||
this.throwUnsupportedError(); | ||
} | ||
yield this.stop(); | ||
const speechSynthesis = this.speechSynthesis; | ||
const utterance = this.createSpeechSynthesisUtterance(options); | ||
return new Promise((resolve, reject) => { | ||
utterance.onend = () => { | ||
resolve(); | ||
}; | ||
utterance.onerror = (event) => { | ||
reject(event); | ||
}; | ||
speechSynthesis.speak(utterance); | ||
}); | ||
async speak(options) { | ||
if (!this.speechSynthesis) { | ||
this.throwUnsupportedError(); | ||
} | ||
await this.stop(); | ||
const speechSynthesis = this.speechSynthesis; | ||
const utterance = this.createSpeechSynthesisUtterance(options); | ||
return new Promise((resolve, reject) => { | ||
utterance.onend = () => { | ||
resolve(); | ||
}; | ||
utterance.onerror = (event) => { | ||
reject(event); | ||
}; | ||
speechSynthesis.speak(utterance); | ||
}); | ||
} | ||
stop() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.speechSynthesis) { | ||
this.throwUnsupportedError(); | ||
} | ||
this.speechSynthesis.cancel(); | ||
}); | ||
async stop() { | ||
if (!this.speechSynthesis) { | ||
this.throwUnsupportedError(); | ||
} | ||
this.speechSynthesis.cancel(); | ||
} | ||
getSupportedLanguages() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const voices = this.getSpeechSynthesisVoices(); | ||
const languages = voices.map(voice => voice.lang); | ||
const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i); | ||
return { languages: filteredLanguages }; | ||
}); | ||
async getSupportedLanguages() { | ||
const voices = this.getSpeechSynthesisVoices(); | ||
const languages = voices.map(voice => voice.lang); | ||
const filteredLanguages = languages.filter((v, i, a) => a.indexOf(v) == i); | ||
return { languages: filteredLanguages }; | ||
} | ||
getSupportedVoices() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const voices = this.getSpeechSynthesisVoices(); | ||
return { voices }; | ||
}); | ||
async getSupportedVoices() { | ||
const voices = this.getSpeechSynthesisVoices(); | ||
return { voices }; | ||
} | ||
openInstall() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.throwUnimplementedError(); | ||
}); | ||
async openInstall() { | ||
this.throwUnimplementedError(); | ||
} | ||
setPitchRate(_options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.throwUnimplementedError(); | ||
}); | ||
async setPitchRate(_options) { | ||
this.throwUnimplementedError(); | ||
} | ||
setSpeechRate(_options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.throwUnimplementedError(); | ||
}); | ||
async setSpeechRate(_options) { | ||
this.throwUnimplementedError(); | ||
} | ||
@@ -107,17 +88,24 @@ createSpeechSynthesisUtterance(options) { | ||
} | ||
return this.speechSynthesis.getVoices(); | ||
if (!this.supportedVoices || this.supportedVoices.length < 1) { | ||
this.supportedVoices = this.speechSynthesis.getVoices(); | ||
} | ||
return this.supportedVoices; | ||
} | ||
throwUnsupportedError() { | ||
throw new Error('Not supported on this device.'); | ||
throw this.unavailable('SpeechSynthesis API not available in this browser.'); | ||
} | ||
throwUnimplementedError() { | ||
throw new Error('Not implemented on web.'); | ||
throw this.unimplemented('Not implemented on web.'); | ||
} | ||
} | ||
const TextToSpeech = new TextToSpeechWeb(); | ||
core.registerWebPlugin(TextToSpeech); | ||
var web = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
TextToSpeechWeb: TextToSpeechWeb | ||
}); | ||
exports.TextToSpeech = TextToSpeech; | ||
exports.TextToSpeechWeb = TextToSpeechWeb; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
return exports; | ||
@@ -124,0 +112,0 @@ |
{ | ||
"name": "@capacitor-community/text-to-speech", | ||
"version": "0.2.2", | ||
"version": "0.2.3-dev.6ffcfb9", | ||
"description": "Capacitor plugin for synthesizing speech from text.", | ||
"main": "dist/plugin.js", | ||
"main": "dist/plugin.cjs.js", | ||
"module": "dist/esm/index.js", | ||
"types": "dist/esm/index.d.ts", | ||
"unpkg": "dist/plugin.js", | ||
"scripts": { | ||
"lint": "npm run prettier -- --check && npm run swiftlint -- lint", | ||
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web", | ||
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin && cd ..", | ||
"verify:android": "cd android && ./gradlew clean build test && cd ..", | ||
"verify:web": "npm run build", | ||
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint", | ||
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- autocorrect --format", | ||
"eslint": "eslint . --ext ts", | ||
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"", | ||
"swiftlint": "node-swiftlint", | ||
"build": "npm run clean && tsc && rollup -c rollup.config.js", | ||
"docgen": "docgen --api TextToSpeechPlugin --output-readme README.md --output-json dist/docs.json", | ||
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js", | ||
"clean": "rimraf ./dist", | ||
@@ -18,23 +26,23 @@ "watch": "tsc --watch", | ||
}, | ||
"contributors": [ | ||
"Priyank Patel <priyank.patel@stackspace.ca>", | ||
"Robin Genz <mail@robingenz.dev>" | ||
], | ||
"author": "Robin Genz <mail@robingenz.dev>", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@capacitor/android": "2.4.7", | ||
"@capacitor/core": "2.4.7", | ||
"@capacitor/ios": "2.4.7", | ||
"@capacitor/android": "3.0.0-beta.6", | ||
"@capacitor/core": "3.0.0-beta.6", | ||
"@capacitor/docgen": "0.0.16", | ||
"@capacitor/ios": "3.0.0-beta.6", | ||
"@ionic/eslint-config": "0.3.0", | ||
"@ionic/prettier-config": "1.0.1", | ||
"@ionic/swiftlint-config": "1.1.2", | ||
"prettier": "2.0.5", | ||
"prettier-plugin-java": "0.8.3", | ||
"eslint": "7.11.0", | ||
"prettier": "2.2.0", | ||
"prettier-plugin-java": "1.0.0", | ||
"rimraf": "3.0.2", | ||
"rollup": "2.21.0", | ||
"rollup": "2.32.0", | ||
"standard-version": "9.1.0", | ||
"swiftlint": "1.0.1", | ||
"typescript": "3.9.5" | ||
"typescript": "4.0.3" | ||
}, | ||
"peerDependencies": { | ||
"@capacitor/core": "^2.4.6" | ||
"@capacitor/core": "^3.0.0-beta.6" | ||
}, | ||
@@ -48,2 +56,9 @@ "files": [ | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/capacitor-community/text-to-speech.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/capacitor-community/text-to-speech/issues" | ||
}, | ||
"keywords": [ | ||
@@ -54,2 +69,7 @@ "capacitor", | ||
], | ||
"prettier": "@ionic/prettier-config", | ||
"swiftlint": "@ionic/swiftlint-config", | ||
"eslintConfig": { | ||
"extends": "@ionic/eslint-config/recommended" | ||
}, | ||
"capacitor": { | ||
@@ -62,12 +82,3 @@ "ios": { | ||
} | ||
}, | ||
"prettier": "@ionic/prettier-config", | ||
"swiftlint": "@ionic/swiftlint-config", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/capacitor-community/text-to-speech" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/capacitor-community/text-to-speech/issues" | ||
} | ||
} |
262
README.md
@@ -28,2 +28,4 @@ <p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p> | ||
### Capacitor 3.x | ||
``` | ||
@@ -34,2 +36,9 @@ npm install @capacitor-community/text-to-speech | ||
### Capacitor 2.x | ||
``` | ||
npm install @capacitor-community/text-to-speech@0.2.3 | ||
npx cap sync | ||
``` | ||
On **iOS**, no further steps are needed. | ||
@@ -52,3 +61,2 @@ | ||
new ArrayList<Class<? extends Plugin>>() { | ||
{ | ||
@@ -63,2 +71,3 @@ // Additional plugins you've installed go here | ||
} | ||
``` | ||
@@ -70,97 +79,188 @@ | ||
## Supported methods | ||
## Usage | ||
| Name | Android | iOS | Web | | ||
| :-------------------- | :------ | :-- | :-- | | ||
| speak | ✅ | ✅ | ✅ | | ||
| stop | ✅ | ✅ | ✅ | | ||
| getSupportedLanguages | ✅ | ✅ | ✅ | | ||
| openInstall | ✅ | ✅ | ❌ | | ||
| setPitchRate | ✅ | ✅ | ❌ | | ||
| setSpeechRate | ✅ | ✅ | ❌ | | ||
```typescript | ||
import { TextToSpeech } from '@capacitor-community/text-to-speech'; | ||
## Usage | ||
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 | ||
<docgen-index> | ||
* [`speak(...)`](#speak) | ||
* [`stop()`](#stop) | ||
* [`getSupportedLanguages()`](#getsupportedlanguages) | ||
* [`getSupportedVoices()`](#getsupportedvoices) | ||
* [`openInstall()`](#openinstall) | ||
* [`setPitchRate(...)`](#setpitchrate) | ||
* [`setSpeechRate(...)`](#setspeechrate) | ||
* [Interfaces](#interfaces) | ||
</docgen-index> | ||
<docgen-api> | ||
<!--Update the source file JSDoc comments and rerun docgen to update the docs below--> | ||
### speak(...) | ||
```typescript | ||
// Must import the package once to make sure the web support initializes | ||
import '@capacitor-community/text-to-speech'; | ||
speak(options: TTSOptions) => Promise<void> | ||
``` | ||
import { Plugins } from '@capacitor/core'; | ||
Starts the TTS engine and plays the desired text. | ||
const { TextToSpeech } = Plugins; | ||
| Param | Type | | ||
| ------------- | ------------------------------------------------- | | ||
| **`options`** | <code><a href="#ttsoptions">TTSOptions</a></code> | | ||
/** | ||
* Platform: Android/iOS/Web | ||
* This method will trigger text to speech engine and play desired text. | ||
* @param text - desired text to play in speech | ||
* locale - supported locale (can be obtained by calling getSupportedLanguages()) | ||
* speechRate - speech rate (1.0 is the normal speech rate, lower values slow down the speech, greater values accelerate it) | ||
* pitchRate - pitch rate (1.0 is the normal pitch rate, smaller value lowers the tone and greater value increases it) | ||
* volume - volume of the synthesis (0 - 1) | ||
* voice - index of the voice (can be obtained by calling getSupportedVoices()) (Android/Web Only) | ||
* @returns void | ||
*/ | ||
TextToSpeech.speak({ | ||
text: 'This is a sample text.', | ||
locale: 'en_US', | ||
speechRate: 1.0, | ||
pitchRate: 1, | ||
volume: 1.0, | ||
voice: 10, | ||
category: 'ambient', | ||
}); | ||
-------------------- | ||
/** | ||
* Platform: Android/iOS/Web | ||
* This method will stop the engine if it's in the middle of playback. | ||
* @param none | ||
* @returns void | ||
*/ | ||
TextToSpeech.stop(); | ||
/** | ||
* Platform: Android/iOS/Web | ||
* This method will return list of supported languages. | ||
* @param none | ||
* @returns languages - list of available languages | ||
*/ | ||
TextToSpeech.getSupportedLanguages(); | ||
### stop() | ||
/** | ||
* Platform: Android/iOS/Web | ||
* This method will return list of supported voices. | ||
* @param none | ||
* @returns voices - list of available voices | ||
*/ | ||
TextToSpeech.getSupportedVoices(); | ||
```typescript | ||
stop() => Promise<void> | ||
``` | ||
/** | ||
* Platform: Android/iOS | ||
* This method will trigger the platform TextToSpeech engine to start the activity that installs the resource files on the device that are required for TTS to be operational. | ||
* @param none | ||
* @returns void | ||
*/ | ||
TextToSpeech.openInstall(); | ||
Stops the TTS engine. | ||
/** | ||
* * Platform: Android/iOS | ||
* This method will change the pitch rate while the text is being played. | ||
* @param pitchRate - rate of the pitch (1.0 is the normal pitch, lower values lower the tone of the synthesized voice, greater values increase it) | ||
* @returns void | ||
*/ | ||
TextToSpeech.setPitchRate({ | ||
pitchRate: 1.5, | ||
}); | ||
-------------------- | ||
/** | ||
* * Platform: Android/iOS | ||
* This method will change the speech rate while the text is being played. | ||
* @param speechRate - speech rate (1.0 is the normal speech rate, lower values slow down the speech, greater values accelerate it) | ||
* @returns void | ||
*/ | ||
TextToSpeech.setSpeechRate({ | ||
speechRate: 0.5, | ||
}); | ||
### getSupportedLanguages() | ||
```typescript | ||
getSupportedLanguages() => Promise<{ languages: string[]; }> | ||
``` | ||
Returns a list of supported languages. | ||
**Returns:** <code>Promise<{ languages: string[]; }></code> | ||
-------------------- | ||
### getSupportedVoices() | ||
```typescript | ||
getSupportedVoices() => Promise<{ voices: SpeechSynthesisVoice[]; }> | ||
``` | ||
Returns a list of supported voices. | ||
**Returns:** <code>Promise<{ voices: SpeechSynthesisVoice[]; }></code> | ||
-------------------- | ||
### openInstall() | ||
```typescript | ||
openInstall() => Promise<void> | ||
``` | ||
Verifies proper installation and availability of resource files on the system. | ||
-------------------- | ||
### setPitchRate(...) | ||
```typescript | ||
setPitchRate(options: { pitchRate: number; }) => Promise<void> | ||
``` | ||
Changes the pitch rate while the text is being played. | ||
Only available for Android. | ||
| Param | Type | | ||
| ------------- | ----------------------------------- | | ||
| **`options`** | <code>{ pitchRate: number; }</code> | | ||
-------------------- | ||
### setSpeechRate(...) | ||
```typescript | ||
setSpeechRate(options: { speechRate: number; }) => Promise<void> | ||
``` | ||
Changes the speech rate while the text is being played. | ||
Only available for Android. | ||
| Param | Type | | ||
| ------------- | ------------------------------------ | | ||
| **`options`** | <code>{ speechRate: number; }</code> | | ||
-------------------- | ||
### Interfaces | ||
#### TTSOptions | ||
| Prop | Type | Description | | ||
| ---------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| **`text`** | <code>string</code> | Text to be spoken. | | ||
| **`locale`** | <code>string</code> | Language spoken in. Possible languages can be queried using `getSupportedLanguages`. Default: `en-US` | | ||
| **`speechRate`** | <code>number</code> | The speech rate. Default: `1.0` | | ||
| **`pitchRate`** | <code>number</code> | The pitch rate. Default: `1.0` | | ||
| **`volume`** | <code>number</code> | The volume. Default: `1.0` | | ||
| **`voice`** | <code>number</code> | The index of the selected voice. Possible voices can be queried using `getSupportedVoices`. Only available for Web. | | ||
| **`category`** | <code>string</code> | Select 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 <a href="#speechsynthesisvoice">SpeechSynthesisVoice</a> interface represents a voice that the system supports. | ||
| Prop | Type | Description | | ||
| ------------------ | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| **`default`** | <code>boolean</code> | Specifies whether the voice is the default voice for the current app (`true`) or not (`false`). | | ||
| **`lang`** | <code>string</code> | BCP 47 language tag indicating the language of the voice. Example: `en-US` | | ||
| **`localService`** | <code>boolean</code> | Specifies whether the voice is supplied by a local (`true`) or remote (`false`) speech synthesizer service. | | ||
| **`name`** | <code>string</code> | Human-readable name that represents the voice. Example: `Microsoft Zira Desktop - English (United States)` | | ||
| **`voiceURI`** | <code>string</code> | 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` | | ||
</docgen-api> | ||
## Changelog | ||
@@ -167,0 +267,0 @@ |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
76065
664
268
0
15