Typescript error "Type 'string' is not assignable to type 'AudioEncoding'"
See original GitHub issueEnvironment details
- OS: OS X Catalina 10.15.2
- Node.js version: v13.5.0
- Typescript version: 3.7.2
- npm version: 6.13.4
@google-cloud/text-to-speech
version: 2.1.0
Steps to reproduce
I’m was using the demo code, which worked fine until I updated the library from 0.5^ to 2.1.^
import {TextToSpeechClient} from '@google-cloud/text-to-speech'
const client = new TextToSpeechClient({
projectId: 'PROJECT_ID',
keyFilename: googleKey,
});
// Construct the request
const request = {
input: {
text: text
},
// Select the language and SSML Voice Gender (optional)
voice: {
languageCode: 'fr-FR',
name: "fr-FR-Wavenet-A",
ssmlGender: "NEUTRAL",
},
// Select the type of audio encoding
audioConfig: {
audioEncoding: 'LINEAR16',
sampleRateHertz: 8000,
},
};
const response = await client.synthesizeSpeech(request);
But now with this code, Typescript is complaining :
Argument of type ‘{ input: { text: string; }; voice: { languageCode: string; name: string; }; audioConfig: { audioEncoding: string; sampleRateHertz: number; }; }’ is not assignable to parameter of type ‘ISynthesizeSpeechRequest’. The types of ‘audioConfig.audioEncoding’ are incompatible between these types.
Argument of type ‘{ input: { text: string; }; voice: { languageCode: string; name: string; ssmlGender: string; }; audioConfig: { sampleRateHertz: number; }; }’ is not assignable to parameter of type ‘ISynthesizeSpeechRequest’. The types of ‘voice.ssmlGender’ are incompatible between these types. Type ‘string’ is not assignable to type ‘SsmlVoiceGender’.
I got it working with this :
import * as protos from "@google-cloud/text-to-speech/build/protos/protos"
const request = {
input: {
text: text
},
// Select the language and SSML Voice Gender (optional)
voice: {
languageCode: 'fr-FR',
name: "fr-FR-Wavenet-A",
ssmlGender: protos.google.cloud.texttospeech.v1.SsmlVoiceGender.NEUTRAL,
},
// Select the type of audio encoding
audioConfig: {
audioEncoding: protos.google.cloud.texttospeech.v1.AudioEncoding.LINEAR16,
sampleRateHertz: 8000,
},
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:7 (5 by maintainers)
If somebody has any similar problems, below I posted some workaround, what I found on https://westa.io/@alclimb/fp9o
THANKS TO AUTHOR, YOU SAVED MY LIFE
This fix was released, enums now accept strings.