2 * Copyright (c) 2010-2023 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 static org.junit.jupiter.api.Assertions.*;
16 import static org.junit.jupiter.api.Assumptions.assumeTrue;
18 import java.io.IOException;
19 import java.util.HashMap;
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;
32 * Test TTSServiceMacOS
34 * @author Kelly Davis - Initial contribution and API
36 public class TTSServiceMacOSTest {
38 private StorageService storageService;
41 * Test TTSServiceMacOS.getAvailableVoices()
44 public void getAvailableVoicesTest() {
45 assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
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());
55 * Test TTSServiceMacOS.getSupportedFormats()
58 public void getSupportedFormatsTest() {
59 assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
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());
69 * Test TTSServiceMacOS.synthesize(String,Voice,AudioFormat)
72 public void synthesizeTest() throws IOException, TTSException {
73 assumeTrue("Mac OS X".equals(System.getProperty("os.name")));
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");