Search in sources :

Example 6 with Voice

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());
    }
}
Also used : AudioStream(org.eclipse.smarthome.core.audio.AudioStream) TTSException(org.eclipse.smarthome.core.voice.TTSException) IOException(java.io.IOException) AudioFormat(org.eclipse.smarthome.core.audio.AudioFormat) Voice(org.eclipse.smarthome.core.voice.Voice) Test(org.junit.Test)

Example 7 with Voice

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Voice(org.eclipse.smarthome.core.voice.Voice) HashSet(java.util.HashSet)

Aggregations

Voice (org.eclipse.smarthome.core.voice.Voice)7 AudioStream (org.eclipse.smarthome.core.audio.AudioStream)3 TTSException (org.eclipse.smarthome.core.voice.TTSException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 AudioFormat (org.eclipse.smarthome.core.audio.AudioFormat)2 UnsupportedAudioFormatException (org.eclipse.smarthome.core.audio.UnsupportedAudioFormatException)2 UnsupportedAudioStreamException (org.eclipse.smarthome.core.audio.UnsupportedAudioStreamException)2 TTSService (org.eclipse.smarthome.core.voice.TTSService)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 ParameterOption (org.eclipse.smarthome.config.core.ParameterOption)1 AudioSink (org.eclipse.smarthome.core.audio.AudioSink)1 PercentType (org.eclipse.smarthome.core.library.types.PercentType)1 KSService (org.eclipse.smarthome.core.voice.KSService)1 STTService (org.eclipse.smarthome.core.voice.STTService)1 HumanLanguageInterpreter (org.eclipse.smarthome.core.voice.text.HumanLanguageInterpreter)1