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.voicerss.internal;
15 import static org.hamcrest.MatcherAssert.assertThat;
16 import static org.hamcrest.core.IsIterableContaining.hasItem;
17 import static org.hamcrest.core.IsNot.not;
18 import static org.openhab.core.audio.AudioFormat.*;
19 import static org.openhab.voice.voicerss.internal.CompatibleAudioFormatMatcher.compatibleAudioFormat;
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25 import org.openhab.core.audio.AudioFormat;
26 import org.openhab.core.voice.TTSService;
29 * Tests for {@link VoiceRSSTTSService}.
31 * @author Andreas Brenk - Initial contribution
33 public class VoiceRSSTTSServiceTest {
35 private static final AudioFormat MP3_44KHZ_16BIT = new AudioFormat(AudioFormat.CONTAINER_NONE,
36 AudioFormat.CODEC_MP3, null, 16, null, 44_100L);
37 private static final AudioFormat OGG_44KHZ_16BIT = new AudioFormat(AudioFormat.CONTAINER_OGG,
38 AudioFormat.CODEC_VORBIS, null, 16, null, 44_100L);
39 private static final AudioFormat AAC_44KHZ_16BIT = new AudioFormat(AudioFormat.CONTAINER_NONE,
40 AudioFormat.CODEC_MP3, null, 16, null, 44_100L);
41 private static final AudioFormat WAV_22KHZ_8BIT = new AudioFormat(AudioFormat.CONTAINER_WAVE,
42 AudioFormat.CODEC_PCM_UNSIGNED, null, 8, null, 22_050L);
43 private static final AudioFormat WAV_48KHZ_16BIT = new AudioFormat(AudioFormat.CONTAINER_WAVE,
44 AudioFormat.CODEC_PCM_SIGNED, false, 16, null, 48_000L);
47 * The {@link VoiceRSSTTSService} under test.
49 private TTSService ttsService;
53 final VoiceRSSTTSService ttsService = new VoiceRSSTTSService();
54 ttsService.activate(null);
56 this.ttsService = ttsService;
60 public void testSupportedFormats() {
61 final Set<AudioFormat> supportedFormats = ttsService.getSupportedFormats();
63 // check generic formats without any further constraints
64 assertThat(supportedFormats, hasItem(compatibleAudioFormat(MP3)));
65 assertThat(supportedFormats, hasItem(compatibleAudioFormat(WAV)));
66 assertThat(supportedFormats, hasItem(compatibleAudioFormat(OGG)));
67 assertThat(supportedFormats, hasItem(compatibleAudioFormat(AAC)));
69 // check specific formats with common constraints
70 assertThat(supportedFormats, hasItem(compatibleAudioFormat(MP3_44KHZ_16BIT)));
71 assertThat(supportedFormats, hasItem(compatibleAudioFormat(OGG_44KHZ_16BIT)));
72 assertThat(supportedFormats, hasItem(compatibleAudioFormat(AAC_44KHZ_16BIT)));
73 assertThat(supportedFormats, hasItem(compatibleAudioFormat(WAV_22KHZ_8BIT)));
74 assertThat(supportedFormats, hasItem(compatibleAudioFormat(WAV_48KHZ_16BIT)));
76 // check specific formats with additional constraints
77 assertThat(supportedFormats, hasItem(compatibleAudioFormat(bitRate(WAV, 705_600)))); // 44.1 kHz 16-bit
79 // check unsupported formats
80 assertThat(supportedFormats, not(hasItem(compatibleAudioFormat(bitDepth(WAV, 24)))));
83 private AudioFormat bitDepth(AudioFormat format, Integer bitDepth) {
84 return new AudioFormat(format.getContainer(), format.getCodec(), format.isBigEndian(), bitDepth,
85 format.getBitRate(), format.getFrequency());
88 private AudioFormat bitRate(AudioFormat format, Integer bitRate) {
89 return new AudioFormat(format.getContainer(), format.getCodec(), format.isBigEndian(), format.getBitDepth(),
90 bitRate, format.getFrequency());