import { ResponseUI } from "./response-ui" ; import { SusiVisualizer } from "./susi-visualizer" ; export class SusiMirror { private visualizer : SusiVisualizer ; private responseUI : ResponseUI ; constructor ( private mainDiv , private canvas , private userQueryTextNode , private susiResponseDiv , private config , private mainSend ) { this . visualizer = new SusiVisualizer ( this . canvas ) ; this . responseUI = new ResponseUI ( susiResponseDiv ) ; } public start ( ) { this . visualizer . start ( ) ; } public receivedNotification ( type , payload ) { this . visualizer . setMode ( type ) ; switch ( type ) { case "idle" : this . idle ( ) ; this . visualizer . setMode ( "idle" ) ; this . userQueryTextNode . nodeValue = "Ask me anything !!" ; this . responseUI . clear ( ) ; break ; case "listening" : this . listening ( ) ; this . visualizer . setMode ( "listening" ) ; this . userQueryTextNode . nodeValue = "Speak Now" ; break ; case "busy" : this . visualizer . setMode ( "busy" ) ; this . userQueryTextNode . nodeValue = "" ; break ; case "recognized" : this . visualizer . setMode ( "recognized" ) ; this . userQueryTextNode . nodeValue = payload . text ; break ; case "speak" : this . speaking ( ) ; this . visualizer . setMode ( "speak" ) ; this . responseUI . update ( payload . susiResponse ) ; break ; case "error" : this . responseUI . showError ( ) ; this . speakError ( ) ; } } public listening ( ) { this . mainDiv . classList . add ( "wrapper-active" ) ; } public idle ( ) { this . mainDiv . classList . remove ( "wrapper-active" ) ; } public speaking ( ) { const sound = new Audio ( "/output.wav" ) ; sound . play ( ) ; sound . addEventListener ( "ended" , ( ) => { this . mainSend ( "finishedSpeaking" , { } ) ; } ) ; } private speakError ( ) { const sound = new Audio ( "/problem.wav" ) ; sound . play ( ) ; sound . addEventListener ( "ended" , ( ) => { this . mainSend ( "finishedSpeaking" , { } ) ; } ) ; } }