Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[picotts] Add null annotations #10392

Merged
merged 1 commit into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
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;
Expand All @@ -29,14 +31,15 @@
*
* @author Florian Schmidt - Initial Contribution
*/
@NonNullByDefault
class PicoTTSAudioStream extends FixedLengthAudioStream {
private final Voice voice;
private final String text;
private final AudioFormat audioFormat;
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;
Expand All @@ -57,7 +60,8 @@ private InputStream createInputStream() throws AudioException {
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) {
Expand All @@ -68,9 +72,6 @@ private InputStream createInputStream() throws AudioException {
}

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);
Expand Down Expand Up @@ -119,6 +120,7 @@ public long length() {

@Override
public InputStream getClonedStream() throws AudioException {
File file = this.file;
if (file != null) {
return getFileInputStream(file);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
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;
Expand All @@ -30,6 +32,7 @@
* @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"),
Expand All @@ -51,8 +54,8 @@ public Set<AudioFormat> getSupportedFormats() {

@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)) {
Expand Down Expand Up @@ -80,7 +83,7 @@ public String getId() {
}

@Override
public String getLabel(Locale locale) {
public String getLabel(@Nullable Locale locale) {
return "PicoTTS";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@

import java.util.Locale;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.voice.Voice;

/**
* Implementation of the Voice interface for PicoTTS
*
* @author Florian Schmidt - Initial Contribution
*/
@NonNullByDefault
public class PicoTTSVoice implements Voice {
private final String languageTag;

Expand Down