]> git.basschouten.com Git - openhab-addons.git/blob
2e2d3c4833ae9020804998f37aa0336b978d54e5
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.voice.mactts.internal;
14
15 import java.io.IOException;
16 import java.util.Set;
17
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;
25
26 /**
27  * Test TTSServiceMacOS
28  *
29  * @author Kelly Davis - Initial contribution and API
30  */
31 public class TTSServiceMacOSTest {
32
33     /**
34      * Test TTSServiceMacOS.getAvailableVoices()
35      */
36     @Test
37     public void getAvailableVoicesTest() {
38         Assume.assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
39
40         MacTTSService ttsServiceMacOS = new MacTTSService();
41         Assert.assertFalse("The getAvailableVoicesTest() failed", ttsServiceMacOS.getAvailableVoices().isEmpty());
42     }
43
44     /**
45      * Test TTSServiceMacOS.getSupportedFormats()
46      */
47     @Test
48     public void getSupportedFormatsTest() {
49         Assume.assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
50
51         MacTTSService ttsServiceMacOS = new MacTTSService();
52         Assert.assertFalse("The getSupportedFormatsTest() failed", ttsServiceMacOS.getSupportedFormats().isEmpty());
53     }
54
55     /**
56      * Test TTSServiceMacOS.synthesize(String,Voice,AudioFormat)
57      */
58     @Test
59     public void synthesizeTest() {
60         Assume.assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
61
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());
77         }
78     }
79 }