]> git.basschouten.com Git - openhab-addons.git/blob
b525621c72be0b120c9323a8c238272287a19388
[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.HashMap;
20 import java.util.Map;
21 import java.util.Set;
22
23 import org.junit.jupiter.api.Test;
24 import org.openhab.core.audio.AudioFormat;
25 import org.openhab.core.audio.AudioStream;
26 import org.openhab.core.storage.StorageService;
27 import org.openhab.core.voice.TTSException;
28 import org.openhab.core.voice.Voice;
29 import org.openhab.core.voice.internal.cache.TTSLRUCacheImpl;
30
31 /**
32  * Test TTSServiceMacOS
33  *
34  * @author Kelly Davis - Initial contribution and API
35  */
36 public class TTSServiceMacOSTest {
37
38     private StorageService storageService;
39
40     /**
41      * Test TTSServiceMacOS.getAvailableVoices()
42      */
43     @Test
44     public void getAvailableVoicesTest() {
45         assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
46
47         Map<String, Object> config = new HashMap<>();
48         config.put("enableCacheTTS", false);
49         TTSLRUCacheImpl voiceLRUCache = new TTSLRUCacheImpl(storageService, config);
50         MacTTSService ttsServiceMacOS = new MacTTSService(voiceLRUCache);
51         assertFalse(ttsServiceMacOS.getAvailableVoices().isEmpty());
52     }
53
54     /**
55      * Test TTSServiceMacOS.getSupportedFormats()
56      */
57     @Test
58     public void getSupportedFormatsTest() {
59         assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
60
61         Map<String, Object> config = new HashMap<>();
62         config.put("enableCacheTTS", false);
63         TTSLRUCacheImpl voiceLRUCache = new TTSLRUCacheImpl(storageService, config);
64         MacTTSService ttsServiceMacOS = new MacTTSService(voiceLRUCache);
65         assertFalse(ttsServiceMacOS.getSupportedFormats().isEmpty());
66     }
67
68     /**
69      * Test TTSServiceMacOS.synthesize(String,Voice,AudioFormat)
70      */
71     @Test
72     public void synthesizeTest() throws IOException, TTSException {
73         assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
74
75         Map<String, Object> config = new HashMap<>();
76         config.put("enableCacheTTS", false);
77         TTSLRUCacheImpl voiceLRUCache = new TTSLRUCacheImpl(storageService, config);
78         MacTTSService ttsServiceMacOS = new MacTTSService(voiceLRUCache);
79         Set<Voice> voices = ttsServiceMacOS.getAvailableVoices();
80         Set<AudioFormat> audioFormats = ttsServiceMacOS.getSupportedFormats();
81         try (AudioStream audioStream = ttsServiceMacOS.synthesize("Hello", voices.iterator().next(),
82                 audioFormats.iterator().next())) {
83             assertNotNull(audioStream, "created null AudioSource");
84             assertNotNull(audioStream.getFormat(), "created an AudioSource w/o AudioFormat");
85             assertNotNull(audioStream, "created an AudioSource w/o InputStream");
86             assertTrue(-1 != audioStream.read(new byte[2]), "returned an AudioSource with no data");
87         }
88     }
89 }