public class SampleUnifiedSpeechCall extends CallListenerAbstract
The code below illustrates how to intercept a call and start a speech search.
First, to be able to intercept a call, you must implement a class that is
annotated with TheCallListener and either implement
CallListener
or extend
CallListenerAbstract
. This class is a
"listener" that allows you to intercept a call.
Next, you must implement a "speech search listener" class that implements SpeechSearchListener. This class allows you to be notified when important events related to a speech search have occurred. Specifically, if a match occurs for a speech search, then the method matchFound will be called with the match details. If an error occurred starting a speech search then startSearchFailed will be called, otherwise if the search is terminated for any reason then terminated method will be called.
In the callIntercepted method shown below the following occurs:
The search query used in the sample is an example of a insurance sales call. The call is searched for the presence of three concepts:
Also in this example when a call is answered, a Text to Speech (TTS) message is played to the calling party to inform them that the call is being monitored for speech search. We implement a "media listener" and use it to listen for the play completed event. Our media listener then starts the Automatic Speech Recognition (ASR). We implement a "voicexml dialog listener" and use it to listen for the event when a menu selection is recognized.
@TheCallListener public class SampleUnifiedSpeechCall extends CallListenerAbstract { private final Logger logger = Logger.getLogger(SampleUnifiedSpeechCall.class); protected class MySpeechSearchListener implements SpeechSearchListener { @Override public void matchFound(UUID searchId, Call call, ListsearchMatches) { for (SpeechSearchMatch match : searchMatches) { logger.info("A match has been found for " + match.getName() + " at " + match.getStartTime() + " seconds"); } } @Override public void startSearchFailed(UUID searchId, Exception execption) { logger.info("The search failed due to errors[" + execption.getMessage() + "]"); } @Override public void terminated(UUID searchId, String reason) { logger.info("The search was terminated due to " + reason); } } protected class MyMediaListener extends MediaListenerAbstract implements VoiceXMLDialogListener { private final Participant participant; public MyMediaListener(final Participant participant) { this.participant = participant; } @Override public void playCompleted(final UUID requestId, final PlayOperationCause cause) { logger.info("playCompleted: We completed playing Text-to-speech. " + "Next, send a VoiceXML dialog request for speech recognition."); VoiceXMLDialogItem dialogItem = null; try { dialogItem = SpeechFactory.createVoiceXMLDialogItem() .setVoiceXMLScript(new URI("http: *www.mycompany.com/menu.vxml")); } catch (final URISyntaxException e) { logger.info("playCompleted: An error occured. Please check that your VoiceXML URL is valid."); } final UUID asrRequestId = SpeechFactory.createSpeechService() .startVoiceXMLDialog(participant, dialogItem, this); logger.info("playCompleted: Search a voice recognition dialog with UUID " + asrRequestId); } @Override public void dialogEvent(final UUID requestId, final Map names, final VoiceXMLDialogCause dialogEvent) { logger.info("dialogEvent: We completed VoiceXML speech recognition."); } } @Override public void callIntercepted(final Call call) { final SearchQuery searchQuery = createSearchQuery(); final SearchOptions options = SpeechFactory.createSearchOptions() .setLanguage("en_US").setSearchQuery(searchQuery); final UUID searchID = SpeechFactory.createSpeechService().startSearch(call, options, new MySpeechSearchListener()); logger.info("callIntercepted: Search started with UUID " + searchID.toString()); } @Override public void callAnswered(final Call call) { final Participant participant = call.getCallingParty(); final MediaService mediaService = MediaFactory.createMediaService(); PlayItem playItem = null; try { playItem = MediaFactory.createPlayItem() .setSource("Your call is currently being monitored"); } catch (final URISyntaxException e) { logger.info("callAnswered: An error occured. Please check that text to speech message is valid."); } final UUID ttsRequestId = mediaService.play(participant, playItem, new MyMediaListener(participant)); logger.info("callAnswered: Started a play request for a text to speech with UUID " + ttsRequestId); } public SearchQuery createSearchQuery() { Concept greeting = SpeechFactory.createConcept() .setName("Greeting") .setOperator(SpeechFactory.createAnyOperator()) .setThreshold(45.0f) .addPhrase("Good Morning", 45.0f) .addPhrase("Hello", 45.0f); Concept introduction = SpeechFactory.createConcept() .setName("Introduction of Agent and Department") .setOperator(SpeechFactory.createAnyOperator()) .setThreshold(45.0f) .addPhrase("Welcome to", 45.0f) .addPhrase("My name is", 45.0f); Concept opening = SpeechFactory.createConcept() .setName("Opening") .setOperator(SpeechFactory.createAllOperator()) .setThreshold(45.0f) .setSubConcepts(greeting, introduction); Concept selling = SpeechFactory.createConcept() .setName("Selling") .setOperator(SpeechFactory.createAllOperator()) .setThreshold(45.0f) .addPhrase("Would you like to buy", 45.0f) .addPhrase("Could I offer you", 45.0f); Concept closing = SpeechFactory.createConcept() .setName("Closing") .setOperator(SpeechFactory.createAllOperator()) .setThreshold(45.0f) .addPhrase("Thank you for calling", 45.0f) .addPhrase("We appreciate your call", 45.0f); return SpeechFactory.createSearchQuery() .setLangauge("en_US") .setConcepts(opening, selling, closing); } }
Constructor and Description |
---|
SampleUnifiedSpeechCall() |
Modifier and Type | Method and Description |
---|---|
void |
callAnswered(Call call)
When a call is answered, play a Text to Speech prompt to the calling
party to inform them the call is being monitored for speech search.
|
void |
callIntercepted(Call call)
Intercept a call and start a speech search.
|
SearchQuery |
createSearchQuery()
Create a Search Query based on a insurance sales call.
|
addParticipantFailed, callAlerting, callOriginated, callTerminated, mediaDetected, participantDropped
public void callIntercepted(Call call)
call
- the intercepted callpublic void callAnswered(Call call)
callAnswered
in interface CallListener
callAnswered
in class CallListenerAbstract
call
- instance of the callpublic SearchQuery createSearchQuery()
Copyright © 2016 Avaya. All Rights Reserved.