forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DefinitelyTyped#34046 from benhjames/bhj/google-cl…
…oud__text-to-speech Add @google-cloud/text-to-speech definitions
- Loading branch information
Showing
4 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
types/google-cloud__text-to-speech/google-cloud__text-to-speech-tests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "extends": "dtslint/dt.json" } |