Last active
September 25, 2019 10:42
-
-
Save 345ml/7b88d87323cc5bfc09489db1693e983f to your computer and use it in GitHub Desktop.
GCP API gRPC Node.js
This file contains hidden or 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
// yarn add grpc google-protobuf grpc-tools grpc_tools_node_protoc_ts | |
// git clone https://github.com/googleapis/googleapis /googleapis | |
// npx grpc_tools_node_protoc \ | |
// --js_out=import_style=commonjs,binary:. \ | |
// --grpc_out=. \ | |
// --plugin=protoc-gen-grpc=./node_modules/grpc-tools/bin/grpc_node_plugin \ | |
// -I /googleapis \ | |
// /Users/horota/work/googleapis/google/cloud/texttospeech/v1/*.proto | |
// npx grpc_tools_node_protoc \ | |
// --js_out=import_style=commonjs,binary:. \ | |
// --grpc_out=. \ | |
// --plugin=protoc-gen-grpc=./node_modules/grpc-tools/bin/grpc_node_plugin \ | |
// -I /googleapis \ | |
// /googleapis/google/api/*.proto | |
const grpc = require('grpc'); | |
const cloud_tts_grpc_pb = require('./google/cloud/texttospeech/v1/cloud_tts_grpc_pb'); | |
const cloud_tts_pb = require('./google/cloud/texttospeech/v1/cloud_tts_pb'); | |
const client = new cloud_tts_grpc_pb.TextToSpeechClient( | |
'texttospeech.googleapis.com', | |
grpc.credentials.createInsecure(), | |
); | |
const req = new cloud_tts_pb.SynthesizeSpeechRequest(); | |
req.setInput(new cloud_tts_pb.SynthesisInput({ | |
text: 'Hello' | |
})); | |
req.setVoice(new cloud_tts_pb.VoiceSelectionParams({ | |
languageCode: 'en-US', | |
name: 'en-US-Wavenet-F', | |
ssmlGender: cloud_tts_pb.SsmlVoiceGender.FEMALE, | |
})); | |
req.setAudioConfig(new cloud_tts_pb.AudioConfig({ | |
audioEncoding: cloud_tts_pb.AudioEncoding.MP3, | |
pitch: 1, | |
})); | |
client.synthesizeSpeech(req, (error, result) => { | |
if (error) { | |
console.log('ERROR'); | |
console.error(error); | |
return; | |
} | |
console.log('RESULT'); | |
console.log(result); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does not work.