diff --git a/types/google-cloud__text-to-speech/google-cloud__text-to-speech-tests.ts b/types/google-cloud__text-to-speech/google-cloud__text-to-speech-tests.ts new file mode 100644 index 0000000000..79c368c8e3 --- /dev/null +++ b/types/google-cloud__text-to-speech/google-cloud__text-to-speech-tests.ts @@ -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); + }); diff --git a/types/google-cloud__text-to-speech/index.d.ts b/types/google-cloud__text-to-speech/index.d.ts new file mode 100644 index 0000000000..9e0c80cac2 --- /dev/null +++ b/types/google-cloud__text-to-speech/index.d.ts @@ -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 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// TypeScript Version: 2.8 + +/// + +export type GoogleError = any; + +export type APICallback = ( + err: GoogleError | null, + response?: T +) => void; + +export interface PromiseLike extends Promise { + /** + * Cancel the ongoing promise + */ + cancel(): void; +} + +export interface MethodOverload { + (data: T, options?: CallOptions): PromiseLike<[R]>; + (data: T, options: CallOptions, callback: APICallback): void; + (data: T, callback: APICallback): 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; + synthesizeSpeech: MethodOverload< + SynthesizeSpeechRequest, + SynthesizeSpeechResponse + >; +} + +declare const TextToSpeech: { TextToSpeechClient: typeof TextToSpeechClient }; + +export default TextToSpeech; diff --git a/types/google-cloud__text-to-speech/tsconfig.json b/types/google-cloud__text-to-speech/tsconfig.json new file mode 100644 index 0000000000..a682d930a1 --- /dev/null +++ b/types/google-cloud__text-to-speech/tsconfig.json @@ -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"] +} diff --git a/types/google-cloud__text-to-speech/tslint.json b/types/google-cloud__text-to-speech/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/google-cloud__text-to-speech/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }