2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.voice.mactts.internal;
15 import java.io.IOException;
18 import org.junit.Assert;
19 import org.junit.Assume;
20 import org.junit.Test;
21 import org.openhab.core.audio.AudioFormat;
22 import org.openhab.core.audio.AudioStream;
23 import org.openhab.core.voice.TTSException;
24 import org.openhab.core.voice.Voice;
27 * Test TTSServiceMacOS
29 * @author Kelly Davis - Initial contribution and API
31 public class TTSServiceMacOSTest {
34 * Test TTSServiceMacOS.getAvailableVoices()
37 public void getAvailableVoicesTest() {
38 Assume.assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
40 MacTTSService ttsServiceMacOS = new MacTTSService();
41 Assert.assertFalse("The getAvailableVoicesTest() failed", ttsServiceMacOS.getAvailableVoices().isEmpty());
45 * Test TTSServiceMacOS.getSupportedFormats()
48 public void getSupportedFormatsTest() {
49 Assume.assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
51 MacTTSService ttsServiceMacOS = new MacTTSService();
52 Assert.assertFalse("The getSupportedFormatsTest() failed", ttsServiceMacOS.getSupportedFormats().isEmpty());
56 * Test TTSServiceMacOS.synthesize(String,Voice,AudioFormat)
59 public void synthesizeTest() {
60 Assume.assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
62 MacTTSService ttsServiceMacOS = new MacTTSService();
63 Set<Voice> voices = ttsServiceMacOS.getAvailableVoices();
64 Set<AudioFormat> audioFormats = ttsServiceMacOS.getSupportedFormats();
65 try (AudioStream audioStream = ttsServiceMacOS.synthesize("Hello", voices.iterator().next(),
66 audioFormats.iterator().next())) {
67 Assert.assertNotNull("The test synthesizeTest() created null AudioSource", audioStream);
68 Assert.assertNotNull("The test synthesizeTest() created an AudioSource w/o AudioFormat",
69 audioStream.getFormat());
70 Assert.assertNotNull("The test synthesizeTest() created an AudioSource w/o InputStream", audioStream);
71 Assert.assertTrue("The test synthesizeTest() returned an AudioSource with no data",
72 (-1 != audioStream.read(new byte[2])));
73 } catch (TTSException e) {
74 Assert.fail("synthesizeTest() failed with TTSException: " + e.getMessage());
75 } catch (IOException e) {
76 Assert.fail("synthesizeTest() failed with IOException: " + e.getMessage());