use of org.eclipse.smarthome.core.voice.Voice in project smarthome by eclipse.
the class TTSServiceMacOSTest method synthesizeTest.
/**
* Test TTSServiceMacOS.synthesize(String,Voice,AudioFormat)
*/
@Test
public void synthesizeTest() {
Assume.assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
MacTTSService ttsServiceMacOS = new MacTTSService();
Set<Voice> voices = ttsServiceMacOS.getAvailableVoices();
Set<AudioFormat> audioFormats = ttsServiceMacOS.getSupportedFormats();
try (AudioStream audioStream = ttsServiceMacOS.synthesize("Hello", voices.iterator().next(), audioFormats.iterator().next())) {
Assert.assertNotNull("The test synthesizeTest() created null AudioSource", audioStream);
Assert.assertNotNull("The test synthesizeTest() created an AudioSource w/o AudioFormat", audioStream.getFormat());
Assert.assertNotNull("The test synthesizeTest() created an AudioSource w/o InputStream", audioStream);
Assert.assertTrue("The test synthesizeTest() returned an AudioSource with no data", (-1 != audioStream.read(new byte[2])));
} catch (TTSException e) {
Assert.fail("synthesizeTest() failed with TTSException: " + e.getMessage());
} catch (IOException e) {
Assert.fail("synthesizeTest() failed with IOException: " + e.getMessage());
}
}
use of org.eclipse.smarthome.core.voice.Voice in project smarthome by eclipse.
the class MacTTSService method initVoices.
/**
* Initializes this.voices
*
* @return The voices of this instance
*/
private final Set<Voice> initVoices() {
Set<Voice> voices = new HashSet<Voice>();
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
try {
Process process = Runtime.getRuntime().exec("say -v ?");
inputStreamReader = new InputStreamReader(process.getInputStream());
bufferedReader = new BufferedReader(inputStreamReader);
String nextLine;
while ((nextLine = bufferedReader.readLine()) != null) {
voices.add(new MacTTSVoice(nextLine));
}
} catch (IOException e) {
logger.error("Error while executing the 'say -v ?' command: {}", e.getMessage());
} finally {
IOUtils.closeQuietly(bufferedReader);
}
return voices;
}
Aggregations