import java.io.IOException;
import java.io.InputStream;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.audio.AudioException;
import org.openhab.core.audio.AudioFormat;
import org.openhab.core.audio.AudioStream;
*
* @author Florian Schmidt - Initial Contribution
*/
+@NonNullByDefault
class PicoTTSAudioStream extends FixedLengthAudioStream {
private final Voice voice;
private final String text;
private final InputStream inputStream;
private long length;
- private File file;
+ private @Nullable File file;
public PicoTTSAudioStream(String text, Voice voice, AudioFormat audioFormat) throws AudioException {
this.text = text;
try {
Process process = Runtime.getRuntime().exec(command);
process.waitFor();
- file = new File(outputFile);
+ File file = new File(outputFile);
+ this.file = file;
this.length = file.length();
return getFileInputStream(file);
} catch (IOException e) {
}
private InputStream getFileInputStream(File file) throws AudioException {
- if (file == null) {
- throw new IllegalArgumentException("file must not be null");
- }
if (file.exists()) {
try {
return new FileInputStream(file);
@Override
public InputStream getClonedStream() throws AudioException {
+ File file = this.file;
if (file != null) {
return getFileInputStream(file);
} else {
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.audio.AudioException;
import org.openhab.core.audio.AudioFormat;
import org.openhab.core.audio.AudioStream;
* @author Florian Schmidt - Initial Contribution
*/
@Component
+@NonNullByDefault
public class PicoTTSService implements TTSService {
private final Set<Voice> voices = Stream
.of(new PicoTTSVoice("de-DE"), new PicoTTSVoice("en-US"), new PicoTTSVoice("en-GB"),
@Override
public AudioStream synthesize(String text, Voice voice, AudioFormat requestedFormat) throws TTSException {
- if (text == null || text.isEmpty()) {
- throw new TTSException("The passed text can not be null or empty");
+ if (text.isEmpty()) {
+ throw new TTSException("The passed text can not be empty");
}
if (!this.voices.contains(voice)) {
}
@Override
- public String getLabel(Locale locale) {
+ public String getLabel(@Nullable Locale locale) {
return "PicoTTS";
}
}