I am using the request library in Node.js to Google's text-to-speech API. I would like to print out the request that is being sent like in this python example.
Here is my code:
const request = require('request');
const headers = {headers: {'input': {'text':'I want to say this'}, 'voice':{ 'languageCode' : 'en-US'},'audioConfig':{'audioEncoding': 'MP3'}}}
request.post('https://texttospeech.googleapis.com/v1beta1/text:synthesize?key=API_KEY',headers, (error, res, body) => {
if (error) {
console.error(error)
return
}
console.log(`statusCode: ${res.statusCode}`)
console.log(body)
})
This is documented here:
There are at least three ways to debug the operation of request:
Launch the node process like
NODE_DEBUG=request node script.js
(lib
,request
,otherlib
works too).Set
require('request').debug = true
at any time (this does the same thing as #1).Use the
request-debug
module to view request and response headers and bodies.