AsrSignal { @Override public String toString() { final StringBuilder buffer = new StringBuilder(); if (!initialPrompts.isEmpty()) { buffer.append("ip="); for (int index = 0; index < initialPrompts.size(); index++) { buffer.append(initialPrompts.get(index)); if (index < initialPrompts.size() - 1) { buffer.append(","); } } } if (buffer.length() > 0) buffer.append(SPACE_CHARACTER); buffer.append("dr=").append(driver); if (buffer.length() > 0) buffer.append(SPACE_CHARACTER); buffer.append("ln=").append(lang); if (endInputKey != null) { if (buffer.length() > 0) buffer.append(SPACE_CHARACTER); buffer.append("eik=").append(endInputKey); } if (maximumRecTimer > 0) { if (buffer.length() > 0) buffer.append(SPACE_CHARACTER); buffer.append("mrt=").append(maximumRecTimer * 10); } if (waitingInputTimer > 0) { if (buffer.length() > 0) buffer.append(SPACE_CHARACTER); buffer.append("wit=").append(waitingInputTimer * 10); } if (timeAfterSpeech > 0) { if (buffer.length() > 0) buffer.append(SPACE_CHARACTER); buffer.append("pst=").append(timeAfterSpeech * 10); } if (hotWords != null) { if (buffer.length() > 0) buffer.append(SPACE_CHARACTER); buffer.append("hw=").append(Hex.encodeHexString(hotWords.getBytes())); } if (input != null) { if (buffer.length() > 0) buffer.append(SPACE_CHARACTER); buffer.append("in=").append(input); } if (minNumber > 0) { if (buffer.length() > 0) buffer.append(SPACE_CHARACTER); buffer.append("mn=").append(minNumber); } if (maxNumber > 0) { if (buffer.length() > 0) buffer.append(SPACE_CHARACTER); buffer.append("mx=").append(maxNumber); } if (partialResult) { if (buffer.length() > 0) buffer.append(SPACE_CHARACTER); buffer.append("pr=").append(partialResult); } return buffer.toString(); } AsrSignal(String driver, String lang, List<URI> initialPrompts, String endInputKey, int maximumRecTimer, int waitingInputTimer,
                     int timeAfterSpeech, String hotWords, String input, int numberOfDigits, boolean partialResult); @Override String toString(); static final MgcpEvent REQUEST_ASR; }
@Test public void testFormatting() { String expectedResult = "ip=hello.wav dr=no_name_driver ln=en-US eik=# mrt=100 wit=100 pst=50 hw=57616974 in=dtmf_speech mn=1 mx=1 pr=true"; AsrSignal asrSignal = new AsrSignal(driver, DEFAULT_LANG, initialPrompts, endInputKey, maximumRecTimer, waitingInputTimer, timeAfterSpeech, hotWords, input, numberOfDigits, partialResult); String actualResult = asrSignal.toString(); assertEquals(expectedResult, actualResult); }
@Test public void testFormattingWithMultiplePrompts() { initialPrompts = new ArrayList<URI>() {{ add(URI.create("hello.wav")); add(URI.create("world.wav")); }}; String expectedResult = "ip=hello.wav,world.wav dr=no_name_driver ln=en-US eik=# mrt=100 wit=100 pst=50 hw=57616974 in=dtmf_speech mn=1 mx=1 pr=true"; AsrSignal asrSignal = new AsrSignal(driver, DEFAULT_LANG, initialPrompts, endInputKey, maximumRecTimer, waitingInputTimer, timeAfterSpeech, hotWords, input, numberOfDigits, partialResult); String actualResult = asrSignal.toString(); assertEquals(expectedResult, actualResult); }