]> git.basschouten.com Git - openhab-addons.git/blob
43756b1b1f52605baae09bb9ed68ed51c02ca548
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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 static org.junit.jupiter.api.Assertions.*;
16 import static org.junit.jupiter.api.Assumptions.assumeTrue;
17
18 import java.io.IOException;
19 import java.util.Set;
20
21 import org.junit.jupiter.api.Test;
22 import org.openhab.core.audio.AudioFormat;
23 import org.openhab.core.audio.AudioStream;
24 import org.openhab.core.voice.TTSException;
25 import org.openhab.core.voice.Voice;
26
27 /**
28  * Test TTSServiceMacOS
29  *
30  * @author Kelly Davis - Initial contribution and API
31  */
32 public class TTSServiceMacOSTest {
33
34     /**
35      * Test TTSServiceMacOS.getAvailableVoices()
36      */
37     @Test
38     public void getAvailableVoicesTest() {
39         assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
40
41         MacTTSService ttsServiceMacOS = new MacTTSService();
42         assertFalse(ttsServiceMacOS.getAvailableVoices().isEmpty());
43     }
44
45     /**
46      * Test TTSServiceMacOS.getSupportedFormats()
47      */
48     @Test
49     public void getSupportedFormatsTest() {
50         assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
51
52         MacTTSService ttsServiceMacOS = new MacTTSService();
53         assertFalse(ttsServiceMacOS.getSupportedFormats().isEmpty());
54     }
55
56     /**
57      * Test TTSServiceMacOS.synthesize(String,Voice,AudioFormat)
58      */
59     @Test
60     public void synthesizeTest() throws IOException, TTSException {
61         assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
62
63         MacTTSService ttsServiceMacOS = new MacTTSService();
64         Set<Voice> voices = ttsServiceMacOS.getAvailableVoices();
65         Set<AudioFormat> audioFormats = ttsServiceMacOS.getSupportedFormats();
66         try (AudioStream audioStream = ttsServiceMacOS.synthesize("Hello", voices.iterator().next(),
67                 audioFormats.iterator().next())) {
68             assertNotNull(audioStream, "created null AudioSource");
69             assertNotNull(audioStream.getFormat(), "created an AudioSource w/o AudioFormat");
70             assertNotNull(audioStream, "created an AudioSource w/o InputStream");
71             assertTrue(-1 != audioStream.read(new byte[2]), "returned an AudioSource with no data");
72         }
73     }
74 }