Skip to content

Commit

Permalink
Merge pull request DefinitelyTyped#34046 from benhjames/bhj/google-cl…
Browse files Browse the repository at this point in the history
…oud__text-to-speech

Add @google-cloud/text-to-speech definitions
  • Loading branch information
sheetalkamat committed Mar 21, 2019
2 parents 1af72b7 + 3780fcc commit 8c7d2a7
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 changes: 123 additions & 0 deletions types/google-cloud__text-to-speech/index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
19 changes: 19 additions & 0 deletions types/google-cloud__text-to-speech/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"]
}
1 change: 1 addition & 0 deletions types/google-cloud__text-to-speech/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

0 comments on commit 8c7d2a7

Please sign in to comment.