@@ -1797,67 +1797,72 @@ public void execute(final Object message) throws Exception {
17971797 final Recording recording = builder .build ();
17981798 final RecordingsDao recordings = storage .getRecordingsDao ();
17991799 recordings .addRecording (recording );
1800- // Start transcription.
1801- URI transcribeCallback = null ;
1802- Attribute attribute = verb .attribute ("transcribeCallback" );
1803- if (attribute != null ) {
1804- final String value = attribute .value ();
1805- if (value != null && !value .isEmpty ()) {
1806- try {
1807- transcribeCallback = URI .create (value );
1808- } catch (final Exception exception ) {
1809- final Notification notification = notification (ERROR_NOTIFICATION , 11100 , transcribeCallback
1810- + " is an invalid URI." );
1811- notifications .addNotification (notification );
1812- sendMail (notification );
1813- final StopInterpreter stop = new StopInterpreter ();
1814- source .tell (stop , source );
1815- return ;
1816- }
1817- }
1818- }
1819- boolean transcribe = false ;
1820- if (transcribeCallback != null ) {
1821- transcribe = true ;
1822- } else {
1823- attribute = verb .attribute ("transcribe" );
1800+
1801+ Attribute attribute = null ;
1802+
1803+ if (checkAsrService ()) {
1804+ // ASR service is enabled. Start transcription.
1805+ URI transcribeCallback = null ;
1806+ attribute = verb .attribute ("transcribeCallback" );
18241807 if (attribute != null ) {
18251808 final String value = attribute .value ();
18261809 if (value != null && !value .isEmpty ()) {
1827- transcribe = Boolean .parseBoolean (value );
1810+ try {
1811+ transcribeCallback = URI .create (value );
1812+ } catch (final Exception exception ) {
1813+ final Notification notification = notification (ERROR_NOTIFICATION , 11100 , transcribeCallback
1814+ + " is an invalid URI." );
1815+ notifications .addNotification (notification );
1816+ sendMail (notification );
1817+ final StopInterpreter stop = new StopInterpreter ();
1818+ source .tell (stop , source );
1819+ return ;
1820+ }
18281821 }
18291822 }
1830- }
1831- if (transcribe && checkAsrService ()) {
1832- final Sid sid = Sid .generate (Sid .Type .TRANSCRIPTION );
1833- final Transcription .Builder otherBuilder = Transcription .builder ();
1834- otherBuilder .setSid (sid );
1835- otherBuilder .setAccountSid (accountId );
1836- otherBuilder .setStatus (Transcription .Status .IN_PROGRESS );
1837- otherBuilder .setRecordingSid (recordingSid );
1838- otherBuilder .setTranscriptionText ("Transcription Text not available" );
1839- otherBuilder .setDuration (duration );
1840- otherBuilder .setPrice (new BigDecimal ("0.00" ));
1841- buffer = new StringBuilder ();
1842- buffer .append ("/" ).append (version ).append ("/Accounts/" ).append (accountId .toString ());
1843- buffer .append ("/Transcriptions/" ).append (sid .toString ());
1844- final URI uri = URI .create (buffer .toString ());
1845- otherBuilder .setUri (uri );
1846- final Transcription transcription = otherBuilder .build ();
1847- final TranscriptionsDao transcriptions = storage .getTranscriptionsDao ();
1848- transcriptions .addTranscription (transcription );
1849- try {
1850- final Map <String , Object > attributes = new HashMap <String , Object >();
1851- attributes .put ("callback" , transcribeCallback );
1852- attributes .put ("transcription" , transcription );
1853- getAsrService ().tell (new AsrRequest (new File (recordingUri ), "en" , attributes ), source );
1854- outstandingAsrRequests ++;
1855- } catch (final Exception exception ) {
1856- logger .error (exception .getMessage (), exception );
1823+ boolean transcribe = false ;
1824+ if (transcribeCallback != null ) {
1825+ transcribe = true ;
1826+ } else {
1827+ attribute = verb .attribute ("transcribe" );
1828+ if (attribute != null ) {
1829+ final String value = attribute .value ();
1830+ if (value != null && !value .isEmpty ()) {
1831+ transcribe = Boolean .parseBoolean (value );
1832+ }
1833+ }
1834+ }
1835+ if (transcribe && checkAsrService ()) {
1836+ final Sid sid = Sid .generate (Sid .Type .TRANSCRIPTION );
1837+ final Transcription .Builder otherBuilder = Transcription .builder ();
1838+ otherBuilder .setSid (sid );
1839+ otherBuilder .setAccountSid (accountId );
1840+ otherBuilder .setStatus (Transcription .Status .IN_PROGRESS );
1841+ otherBuilder .setRecordingSid (recordingSid );
1842+ otherBuilder .setTranscriptionText ("Transcription Text not available" );
1843+ otherBuilder .setDuration (duration );
1844+ otherBuilder .setPrice (new BigDecimal ("0.00" ));
1845+ buffer = new StringBuilder ();
1846+ buffer .append ("/" ).append (version ).append ("/Accounts/" ).append (accountId .toString ());
1847+ buffer .append ("/Transcriptions/" ).append (sid .toString ());
1848+ final URI uri = URI .create (buffer .toString ());
1849+ otherBuilder .setUri (uri );
1850+ final Transcription transcription = otherBuilder .build ();
1851+ final TranscriptionsDao transcriptions = storage .getTranscriptionsDao ();
1852+ transcriptions .addTranscription (transcription );
1853+ try {
1854+ final Map <String , Object > attributes = new HashMap <String , Object >();
1855+ attributes .put ("callback" , transcribeCallback );
1856+ attributes .put ("transcription" , transcription );
1857+ getAsrService ().tell (new AsrRequest (new File (recordingUri ), "en" , attributes ), source );
1858+ outstandingAsrRequests ++;
1859+ } catch (final Exception exception ) {
1860+ logger .error (exception .getMessage (), exception );
1861+ }
18571862 }
18581863 } else if (logger .isInfoEnabled ()){
1859- logger .info ("AsrService activated but not properly configured. Please set api-key for AsrService " );
1860- }
1864+ logger .info ("AsrService is not enabled " );
1865+ }
18611866
18621867 // If action is present redirect to the action URI.
18631868 String action = null ;
@@ -1943,11 +1948,11 @@ public void execute(final Object message) throws Exception {
19431948 if (CallStateChanged .class .equals (klass ) ) {
19441949 if (action == null || action .isEmpty ()) {
19451950 source .tell (new StopInterpreter (), source );
1951+ } else {
1952+ // Ask the parser for the next action to take.
1953+ final GetNextVerb next = new GetNextVerb ();
1954+ parser .tell (next , source );
19461955 }
1947- } else {
1948- // Ask the parser for the next action to take.
1949- final GetNextVerb next = new GetNextVerb ();
1950- parser .tell (next , source );
19511956 }
19521957 // A little clean up.
19531958 recordingSid = null ;
0 commit comments