Thursday, May 24, 2018

Google Sentiment Analytics


Summary

In this post, I'll demonstrate use of a Google Natural Language API - Sentiment.  The scenario will be a caller's interaction with a contact center agent is recorded and then sent through Google Speech to Text followed by Sentiment analysis.

Implementation

The diagram below depicts the overall implementation.  Calls enters an ACD/recording platform that has API access in and out.  Recordings are then sent into the Google API's for processing.



Below is a detailed flow of the interactions between the ACD platform and the Google API's.



Code Snippet

App Server

Simple Node.js server below representing the App Server component.
  1. app.post(properties.path, jsonParser, (request, response) => {
  2. //send a response back to ACD immediately to release script-side resources
  3. response.status(200).end();
  4. const contactId = request.body.contactId;
  5. const fileName = request.body.fileName;
  6. let audio;
  7. logger.info(`contactId: ${contactId} webserver - fileName:${fileName}`);
  8. admin.get(contactId, fileName) //Fetch the audio file (Base64-encoded) from ACD
  9. .then((json) => {
  10. audio = json.file;
  11. return sentiment.process(contactId, audio); //Get transcript and sentiment of audio bytes
  12. })
  13. .then((json) => { //Upload the audio, transcript, and sentiment to Google Cloud Storage
  14. return storage.upload(contactId, Buffer.from(audio, 'base64'), json.transcript, JSON.stringify(json.sentiment));
  15. })
  16. .then(() => {
  17. admin.remove(contactId, fileName); //Delete the audio file from ACD
  18. })
  19. .catch((err) => {
  20. logger.error(`contactId:${contactId} webserver - ${err}`);
  21. });
  22. });
  23.  
  24. app.listen(properties.listenPort);
  25. logger.info(`webserver - started on port ${properties.listenPort}`);


Source: https://github.com/joeywhelan/sentiment

Copyright ©1993-2024 Joey E Whelan, All rights reserved.