Add @google-cloud/text-to-speech definitions

This commit is contained in:
Ben James
2019-03-20 22:43:41 +00:00
parent c96ff3089a
commit 3780fcc54d
4 changed files with 199 additions and 0 deletions
@@ -0,0 +1,56 @@
import textToSpeech from "@google-cloud/text-to-speech";
const client = new textToSpeech.TextToSpeechClient({});
/* listVoices */
client.listVoices({});
client.listVoices({}, (err, res) => {
if (res) {
res.map(voice =>
console.log(
voice.language_codes,
voice.name,
voice.naturalSampleRateHertz,
voice.ssmlGender
)
);
}
});
client.listVoices({ languageCode: "en-GB" }).then(res => {
res[0].map(voice =>
console.log(
voice.language_codes,
voice.name,
voice.naturalSampleRateHertz,
voice.ssmlGender
)
);
});
/* synthesizeSpeech */
client.synthesizeSpeech(
{
input: { text: "Hello world." },
audioConfig: { audioEncoding: "MP3" },
voice: { name: "Alice" }
},
(err, res) => {
if (res) {
console.log(res.audioContent);
}
}
);
client
.synthesizeSpeech({
input: { ssml: "Hello world." },
audioConfig: { audioEncoding: "OGG_OPUS" },
voice: { name: "Bob", languageCode: "en-GB" }
})
.then(res => {
console.log(res[0].audioContent);
});
+123
View File
@@ -0,0 +1,123 @@
// Type definitions for google-cloud__text-to-speech 0.5
// Project: https://github.com/googleapis/nodejs-text-to-speech
// Definitions by: Ben James <https://github.com/benhjames>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
/// <reference types="node" />
export type GoogleError = any;
export type APICallback<T = any> = (
err: GoogleError | null,
response?: T
) => void;
export interface PromiseLike<T> extends Promise<T> {
/**
* Cancel the ongoing promise
*/
cancel(): void;
}
export interface MethodOverload<T, R> {
(data: T, options?: CallOptions): PromiseLike<[R]>;
(data: T, options: CallOptions, callback: APICallback<R>): void;
(data: T, callback: APICallback<R>): void;
}
export interface CallOptions {
timeout?: number;
retry?: any;
autoPaginate?: boolean;
pageToken?: any;
isBundling: boolean;
longrunning?: any;
promise?: any;
}
export interface ClientOptionsCredentials {
client_email: string;
private_key: string;
}
export interface ClientOptions {
credentials?: ClientOptionsCredentials;
email?: string;
keyFilename?: string;
port?: number;
projectId?: string;
promise?: any;
servicePath?: string;
}
export interface ListVoicesRequest {
languageCode?: string;
}
export type ListVoicesOptions = CallOptions;
export type SsmlVoiceGender =
| "SSML_VOICE_GENDER_UNSPECIFIED"
| "MALE"
| "FEMALE"
| "NEUTRAL";
export interface Voice {
language_codes: string[];
name: string;
ssmlGender: SsmlVoiceGender;
naturalSampleRateHertz: number;
}
export type ListVoicesResponse = Voice[];
export type SynthesisInput = { text: string } | { ssml: string };
export interface VoiceSelectionParams {
languageCode?: string;
name?: string;
ssmlGender?: SsmlVoiceGender;
}
export type AudioEncoding =
| "AUDIO_ENCODING_UNSPECIFIED"
| "LINEAR16"
| "MP3"
| "OGG_OPUS";
export interface AudioConfig {
audioEncoding: AudioEncoding;
effectsProfileId?: string[];
pitch?: number;
sampleRateHertz?: number;
speakingRate?: number;
volumeGainDb?: number;
}
export interface SynthesizeSpeechRequest {
input: SynthesisInput;
voice: VoiceSelectionParams;
audioConfig: AudioConfig;
}
export type SynthesizeSpeechOptions = CallOptions;
export interface SynthesizeSpeechResponse {
audioContent: Buffer;
}
declare class TextToSpeechClient {
constructor(options?: ClientOptions);
listVoices: MethodOverload<ListVoicesRequest, ListVoicesResponse>;
synthesizeSpeech: MethodOverload<
SynthesizeSpeechRequest,
SynthesizeSpeechResponse
>;
}
declare const TextToSpeech: { TextToSpeechClient: typeof TextToSpeechClient };
export default TextToSpeech;
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@google-cloud/text-to-speech": ["google-cloud__text-to-speech"]
}
},
"files": ["index.d.ts", "google-cloud__text-to-speech-tests.ts"]
}
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }