Discussions

Ask a Question
Back to All

I want implement in my nodejs project how i manage

router.post('/create_voice', (req, res) => {

middleware.decryption(req.body, function (request) {

var rules = {
   
}
const messages = {
  required: req.language.required,
  in: req.language.in,
  required_if: req.language.required_if,
  required_unless: req.language.required_unless,
};
if (middleware.checkValidationRules(request, res, rules, messages, {})) {
  chat_model.create_voice(req.user_id, request, function (responsecode, responsemsg, responsedata) {
    middleware.sendresponse(req, res, 200, responsecode, responsemsg, responsedata);
  }
  );
}
});

})

and this type of model use

create_voice: (user_id, request, callback) => {
    console.log('request',request);
    axios.post('https://api.d-id.com/talks', {

    // headers: {
    //     'Content-Type': 'application/json',
    //     'Key':'Authorization',
    //     'Value':'Basic Z2VraWpvNDE1OUBtdWdhZGdldC5jb20:VLJRS0RJzZvouLoTWJIYP'
    // },

    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Basic Z2VraWpvNDE1OUBtdWdhZGdldC5jb20:VLJRS0RJzZvouLoTWJIYP'
    },

    body: JSON.stringify({
        source_url: request.source_url,
        script: {
        type: request.type,
        input:request.input,
        },

        provider: {
        type: request.type,
        voice_id: request.voice_id,
        voice_config: {
            style: request.style,
        },
      },
  }),
    

    })
    .then(response => {

        console.log('Response from server:', response.data);
        // callback(response.status, 'Success', response.data);
    })
    .catch(error => {
        
        console.error('Error:', error);
        // callback(error.response.status, 'Error', error.response.data);
    });
},

how i manage then easily implement in my project