mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-25 11:45:49 +01:00
[voice] Add voice parameter to startDialog and listenAndAnswer (#2971)
* [voice] Add voice parameter to startDialog and listenAndAnswer Fix #2819 Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
792b7511bf
commit
e5ec888330
@ -247,6 +247,7 @@ public class VoiceResource implements RESTResource {
|
||||
@QueryParam("ksId") @Parameter(description = "keywork spotter ID") @Nullable String ksId,
|
||||
@QueryParam("sttId") @Parameter(description = "Speech-to-Text ID") @Nullable String sttId,
|
||||
@QueryParam("ttsId") @Parameter(description = "Text-to-Speech ID") @Nullable String ttsId,
|
||||
@QueryParam("voiceId") @Parameter(description = "voice ID") @Nullable String voiceId,
|
||||
@QueryParam("hliIds") @Parameter(description = "comma separated list of interpreter IDs") @Nullable String hliIds,
|
||||
@QueryParam("sinkId") @Parameter(description = "audio sink ID") @Nullable String sinkId,
|
||||
@QueryParam("keyword") @Parameter(description = "keyword") @Nullable String keyword,
|
||||
@ -279,6 +280,13 @@ public class VoiceResource implements RESTResource {
|
||||
return JSONResponse.createErrorResponse(Status.NOT_FOUND, "Text-to-Speech not found");
|
||||
}
|
||||
}
|
||||
Voice voice = null;
|
||||
if (voiceId != null) {
|
||||
voice = getVoice(voiceId);
|
||||
if (voice == null) {
|
||||
return JSONResponse.createErrorResponse(Status.NOT_FOUND, "Voice not found");
|
||||
}
|
||||
}
|
||||
List<HumanLanguageInterpreter> interpreters = List.of();
|
||||
if (hliIds != null) {
|
||||
interpreters = voiceManager.getHLIsByIds(hliIds);
|
||||
@ -296,7 +304,7 @@ public class VoiceResource implements RESTResource {
|
||||
final Locale locale = localeService.getLocale(language);
|
||||
|
||||
try {
|
||||
voiceManager.startDialog(ks, stt, tts, interpreters, source, sink, locale, keyword, listeningItem);
|
||||
voiceManager.startDialog(ks, stt, tts, voice, interpreters, source, sink, locale, keyword, listeningItem);
|
||||
return Response.ok(null, MediaType.TEXT_PLAIN).build();
|
||||
} catch (IllegalStateException e) {
|
||||
return JSONResponse.createErrorResponse(Status.BAD_REQUEST, e.getMessage());
|
||||
@ -340,6 +348,7 @@ public class VoiceResource implements RESTResource {
|
||||
@QueryParam("sourceId") @Parameter(description = "source ID") @Nullable String sourceId,
|
||||
@QueryParam("sttId") @Parameter(description = "Speech-to-Text ID") @Nullable String sttId,
|
||||
@QueryParam("ttsId") @Parameter(description = "Text-to-Speech ID") @Nullable String ttsId,
|
||||
@QueryParam("voiceId") @Parameter(description = "voice ID") @Nullable String voiceId,
|
||||
@QueryParam("hliIds") @Parameter(description = "interpreter IDs") @Nullable List<String> hliIds,
|
||||
@QueryParam("sinkId") @Parameter(description = "audio sink ID") @Nullable String sinkId,
|
||||
@QueryParam("listeningItem") @Parameter(description = "listening item") @Nullable String listeningItem) {
|
||||
@ -364,6 +373,13 @@ public class VoiceResource implements RESTResource {
|
||||
return JSONResponse.createErrorResponse(Status.NOT_FOUND, "Text-to-Speech not found");
|
||||
}
|
||||
}
|
||||
Voice voice = null;
|
||||
if (voiceId != null) {
|
||||
voice = getVoice(voiceId);
|
||||
if (voice == null) {
|
||||
return JSONResponse.createErrorResponse(Status.NOT_FOUND, "Voice not found");
|
||||
}
|
||||
}
|
||||
List<HumanLanguageInterpreter> interpreters = List.of();
|
||||
if (hliIds != null) {
|
||||
interpreters = voiceManager.getHLIsByIds(hliIds);
|
||||
@ -381,10 +397,14 @@ public class VoiceResource implements RESTResource {
|
||||
final Locale locale = localeService.getLocale(language);
|
||||
|
||||
try {
|
||||
voiceManager.listenAndAnswer(stt, tts, interpreters, source, sink, locale, listeningItem);
|
||||
voiceManager.listenAndAnswer(stt, tts, voice, interpreters, source, sink, locale, listeningItem);
|
||||
return Response.ok(null, MediaType.TEXT_PLAIN).build();
|
||||
} catch (IllegalStateException e) {
|
||||
return JSONResponse.createErrorResponse(Status.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private @Nullable Voice getVoice(String id) {
|
||||
return voiceManager.getAllVoices().stream().filter(voice -> voice.getUID().equals(id)).findAny().orElse(null);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@
|
||||
*/
|
||||
package org.openhab.core.model.script.actions;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
@ -211,7 +210,7 @@ public class Voice {
|
||||
@ActionDoc(text = "starts dialog processing for a given audio source")
|
||||
public static void startDialog(@ParamDoc(name = "source") @Nullable String source,
|
||||
@ParamDoc(name = "sink") @Nullable String sink) {
|
||||
startDialog(null, null, null, null, source, sink, null, null, null);
|
||||
startDialog(null, null, null, null, null, source, sink, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -220,7 +219,10 @@ public class Voice {
|
||||
* @param ks the keyword spotting service to use or null to use the default service
|
||||
* @param stt the speech-to-text service to use or null to use the default service
|
||||
* @param tts the text-to-speech service to use or null to use the default service
|
||||
* @param interpreters comma separated list of human language text interpreters to use or null to use the default service
|
||||
* @param voice the voice to use or null to use the default voice or any voice provided by the text-to-speech
|
||||
* service matching the locale
|
||||
* @param interpreters comma separated list of human language text interpreters to use or null to use the default
|
||||
* service
|
||||
* @param source the name of audio source to use or null to use the default source
|
||||
* @param sink the name of audio sink to use or null to use the default sink
|
||||
* @param locale the locale to use or null to use the default locale
|
||||
@ -231,6 +233,7 @@ public class Voice {
|
||||
public static void startDialog(@ParamDoc(name = "keyword spotting service") @Nullable String ks,
|
||||
@ParamDoc(name = "speech-to-text service") @Nullable String stt,
|
||||
@ParamDoc(name = "text-to-speech service") @Nullable String tts,
|
||||
@ParamDoc(name = "voice") @Nullable String voice,
|
||||
@ParamDoc(name = "interpreters") @Nullable String interpreters,
|
||||
@ParamDoc(name = "source") @Nullable String source, @ParamDoc(name = "sink") @Nullable String sink,
|
||||
@ParamDoc(name = "locale") @Nullable String locale, @ParamDoc(name = "keyword") @Nullable String keyword,
|
||||
@ -267,6 +270,14 @@ public class Voice {
|
||||
return;
|
||||
}
|
||||
}
|
||||
org.openhab.core.voice.Voice prefVoice = null;
|
||||
if (voice != null) {
|
||||
prefVoice = getVoice(voice);
|
||||
if (prefVoice == null) {
|
||||
logger.warn("Failed starting dialog processing: voice '{}' not found", voice);
|
||||
return;
|
||||
}
|
||||
}
|
||||
List<HumanLanguageInterpreter> hliServices = List.of();
|
||||
if (interpreters != null) {
|
||||
hliServices = VoiceActionService.voiceManager.getHLIsByIds(interpreters);
|
||||
@ -294,8 +305,8 @@ public class Voice {
|
||||
}
|
||||
|
||||
try {
|
||||
VoiceActionService.voiceManager.startDialog(ksService, sttService, ttsService, hliServices, audioSource,
|
||||
audioSink, loc, keyword, listeningItem);
|
||||
VoiceActionService.voiceManager.startDialog(ksService, sttService, ttsService, prefVoice, hliServices,
|
||||
audioSource, audioSink, loc, keyword, listeningItem);
|
||||
} catch (IllegalStateException e) {
|
||||
logger.warn("Failed starting dialog processing: {}", e.getMessage());
|
||||
}
|
||||
@ -333,7 +344,7 @@ public class Voice {
|
||||
@ActionDoc(text = "executes a simple dialog sequence without keyword spotting for a given audio source")
|
||||
public static void listenAndAnswer(@ParamDoc(name = "source") @Nullable String source,
|
||||
@ParamDoc(name = "sink") @Nullable String sink) {
|
||||
listenAndAnswer(null, null, null, source, sink, null, null);
|
||||
listenAndAnswer(null, null, null, null, source, sink, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -341,7 +352,10 @@ public class Voice {
|
||||
*
|
||||
* @param stt the speech-to-text service to use or null to use the default service
|
||||
* @param tts the text-to-speech service to use or null to use the default service
|
||||
* @param interpreters comma separated list of human language text interpreters to use or null to use the default service
|
||||
* @param voice the voice to use or null to use the default voice or any voice provided by the text-to-speech
|
||||
* service matching the locale
|
||||
* @param interpreters comma separated list of human language text interpreters to use or null to use the default
|
||||
* service
|
||||
* @param source the name of audio source to use or null to use the default source
|
||||
* @param sink the name of audio sink to use or null to use the default sink
|
||||
* @param locale the locale to use or null to use the default locale
|
||||
@ -350,6 +364,7 @@ public class Voice {
|
||||
@ActionDoc(text = "executes a simple dialog sequence without keyword spotting for a given audio source")
|
||||
public static void listenAndAnswer(@ParamDoc(name = "speech-to-text service") @Nullable String stt,
|
||||
@ParamDoc(name = "text-to-speech service") @Nullable String tts,
|
||||
@ParamDoc(name = "voice") @Nullable String voice,
|
||||
@ParamDoc(name = "interpreters") @Nullable String interpreters,
|
||||
@ParamDoc(name = "source") @Nullable String source, @ParamDoc(name = "sink") @Nullable String sink,
|
||||
@ParamDoc(name = "locale") @Nullable String locale,
|
||||
@ -378,6 +393,14 @@ public class Voice {
|
||||
return;
|
||||
}
|
||||
}
|
||||
org.openhab.core.voice.Voice prefVoice = null;
|
||||
if (voice != null) {
|
||||
prefVoice = getVoice(voice);
|
||||
if (prefVoice == null) {
|
||||
logger.warn("Failed executing simple dialog: voice '{}' not found", voice);
|
||||
return;
|
||||
}
|
||||
}
|
||||
List<HumanLanguageInterpreter> hliServices = List.of();
|
||||
if (interpreters != null) {
|
||||
hliServices = VoiceActionService.voiceManager.getHLIsByIds(interpreters);
|
||||
@ -405,10 +428,15 @@ public class Voice {
|
||||
}
|
||||
|
||||
try {
|
||||
VoiceActionService.voiceManager.listenAndAnswer(sttService, ttsService, hliServices, audioSource, audioSink,
|
||||
loc, listeningItem);
|
||||
VoiceActionService.voiceManager.listenAndAnswer(sttService, ttsService, prefVoice, hliServices, audioSource,
|
||||
audioSink, loc, listeningItem);
|
||||
} catch (IllegalStateException e) {
|
||||
logger.warn("Failed executing simple dialog: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static org.openhab.core.voice.@Nullable Voice getVoice(String id) {
|
||||
return VoiceActionService.voiceManager.getAllVoices().stream().filter(voice -> voice.getUID().equals(id))
|
||||
.findAny().orElse(null);
|
||||
}
|
||||
}
|
||||
|
@ -170,6 +170,8 @@ public interface VoiceManager {
|
||||
* @param ks the keyword spotting service to use or null to use the default service
|
||||
* @param stt the speech-to-text service to use or null to use the default service
|
||||
* @param tts the text-to-speech service to use or null to use the default service
|
||||
* @param voice the voice to use or null to use the default voice or any voice provided by the text-to-speech
|
||||
* service matching the locale
|
||||
* @param hlis list of human language text interpreters to use, they are executed in order until the first
|
||||
* successful response, or empty to use the default service
|
||||
* @param source the audio source to use or null to use the default source
|
||||
@ -180,7 +182,7 @@ public interface VoiceManager {
|
||||
* @throws IllegalStateException if required services are not all available or the provided locale is not supported
|
||||
* by all these services or a dialog is already started for this audio source
|
||||
*/
|
||||
void startDialog(@Nullable KSService ks, @Nullable STTService stt, @Nullable TTSService tts,
|
||||
void startDialog(@Nullable KSService ks, @Nullable STTService stt, @Nullable TTSService tts, @Nullable Voice voice,
|
||||
List<HumanLanguageInterpreter> hlis, @Nullable AudioSource source, @Nullable AudioSink sink,
|
||||
@Nullable Locale locale, @Nullable String keyword, @Nullable String listeningItem)
|
||||
throws IllegalStateException;
|
||||
@ -214,6 +216,8 @@ public interface VoiceManager {
|
||||
*
|
||||
* @param stt the speech-to-text service to use or null to use the default service
|
||||
* @param tts the text-to-speech service to use or null to use the default service
|
||||
* @param voice the voice to use or null to use the default voice or any voice provided by the text-to-speech
|
||||
* service matching the locale
|
||||
* @param hlis list of human language text interpreters to use, they are executed in order until the first
|
||||
* successful response, or empty to use the default service
|
||||
* @param source the audio source to use or null to use the default source
|
||||
@ -223,9 +227,9 @@ public interface VoiceManager {
|
||||
* @throws IllegalStateException if required services are not all available or the provided locale is not supported
|
||||
* by all these services or a dialog is already started for this audio source
|
||||
*/
|
||||
void listenAndAnswer(@Nullable STTService stt, @Nullable TTSService tts, List<HumanLanguageInterpreter> hlis,
|
||||
@Nullable AudioSource source, @Nullable AudioSink sink, @Nullable Locale locale,
|
||||
@Nullable String listeningItem) throws IllegalStateException;
|
||||
void listenAndAnswer(@Nullable STTService stt, @Nullable TTSService tts, @Nullable Voice voice,
|
||||
List<HumanLanguageInterpreter> hlis, @Nullable AudioSource source, @Nullable AudioSink sink,
|
||||
@Nullable Locale locale, @Nullable String listeningItem) throws IllegalStateException;
|
||||
|
||||
/**
|
||||
* Retrieves a TTS service.
|
||||
@ -311,7 +315,7 @@ public interface VoiceManager {
|
||||
/**
|
||||
* Retrieves a HumanLanguageInterpreter collection.
|
||||
* If no services are available returns an empty list.
|
||||
*
|
||||
*
|
||||
* @param ids Comma separated list of HLI service ids to use
|
||||
* @return a List<HumanLanguageInterpreter> or empty, if none of the services is available
|
||||
*/
|
||||
|
@ -76,6 +76,7 @@ public class DialogProcessor implements KSListener, STTListener {
|
||||
private final @Nullable KSService ks;
|
||||
private final STTService stt;
|
||||
private final TTSService tts;
|
||||
private final @Nullable Voice prefVoice;
|
||||
private final List<HumanLanguageInterpreter> hlis;
|
||||
private final AudioSource source;
|
||||
private final AudioSink sink;
|
||||
@ -106,14 +107,16 @@ public class DialogProcessor implements KSListener, STTListener {
|
||||
private @Nullable AudioStream streamKS;
|
||||
private @Nullable AudioStream streamSTT;
|
||||
|
||||
public DialogProcessor(KSService ks, STTService stt, TTSService tts, List<HumanLanguageInterpreter> hlis,
|
||||
AudioSource source, AudioSink sink, Locale locale, String keyword, @Nullable String listeningItem,
|
||||
EventPublisher eventPublisher, TranslationProvider i18nProvider, Bundle bundle) {
|
||||
public DialogProcessor(KSService ks, STTService stt, TTSService tts, @Nullable Voice voice,
|
||||
List<HumanLanguageInterpreter> hlis, AudioSource source, AudioSink sink, Locale locale, String keyword,
|
||||
@Nullable String listeningItem, EventPublisher eventPublisher, TranslationProvider i18nProvider,
|
||||
Bundle bundle) {
|
||||
this.locale = locale;
|
||||
this.ks = ks;
|
||||
this.hlis = hlis;
|
||||
this.stt = stt;
|
||||
this.tts = tts;
|
||||
this.prefVoice = voice;
|
||||
this.source = source;
|
||||
this.sink = sink;
|
||||
this.keyword = keyword;
|
||||
@ -126,14 +129,15 @@ public class DialogProcessor implements KSListener, STTListener {
|
||||
this.ttsFormat = VoiceManagerImpl.getBestMatch(tts.getSupportedFormats(), sink.getSupportedFormats());
|
||||
}
|
||||
|
||||
public DialogProcessor(STTService stt, TTSService tts, List<HumanLanguageInterpreter> hlis, AudioSource source,
|
||||
AudioSink sink, Locale locale, @Nullable String listeningItem, EventPublisher eventPublisher,
|
||||
TranslationProvider i18nProvider, Bundle bundle) {
|
||||
public DialogProcessor(STTService stt, TTSService tts, @Nullable Voice voice, List<HumanLanguageInterpreter> hlis,
|
||||
AudioSource source, AudioSink sink, Locale locale, @Nullable String listeningItem,
|
||||
EventPublisher eventPublisher, TranslationProvider i18nProvider, Bundle bundle) {
|
||||
this.locale = locale;
|
||||
this.ks = null;
|
||||
this.hlis = hlis;
|
||||
this.stt = stt;
|
||||
this.tts = tts;
|
||||
this.prefVoice = voice;
|
||||
this.source = source;
|
||||
this.sink = sink;
|
||||
this.keyword = "";
|
||||
@ -332,9 +336,11 @@ public class DialogProcessor implements KSListener, STTListener {
|
||||
try {
|
||||
Voice voice = null;
|
||||
for (Voice currentVoice : tts.getAvailableVoices()) {
|
||||
if (locale.getLanguage().equals(currentVoice.getLocale().getLanguage())) {
|
||||
if (!locale.getLanguage().equals(currentVoice.getLocale().getLanguage())) {
|
||||
continue;
|
||||
}
|
||||
if (voice == null || (prefVoice != null && prefVoice.getUID().equals(currentVoice.getUID()))) {
|
||||
voice = currentVoice;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (voice == null) {
|
||||
|
@ -88,11 +88,13 @@ public class VoiceConsoleCommandExtension extends AbstractConsoleCommandExtensio
|
||||
buildCommandUsage(SUBCMD_INTERPRET + " <command>", "interprets a human language command"),
|
||||
buildCommandUsage(SUBCMD_VOICES, "lists available voices of the TTS services"),
|
||||
buildCommandUsage(
|
||||
SUBCMD_START_DIALOG + " [<source> [<sink> [<interpreter> [<tts> [<stt> [<ks> [<keyword>]]]]]]]",
|
||||
SUBCMD_START_DIALOG
|
||||
+ " [<source> [<sink> [<interpreters> [<tts> [<stt> [<ks> {<voice> [<keyword>]]]]]]]]",
|
||||
"start a new dialog processing using the default services or the services identified with provided arguments"),
|
||||
buildCommandUsage(SUBCMD_STOP_DIALOG + " [<source>]",
|
||||
"stop the dialog processing for the default audio source or the audio source identified with provided argument"),
|
||||
buildCommandUsage(SUBCMD_LISTEN_ANSWER + " [<source> [<sink> [<interpreter> [<tts> [<stt>]]]]]",
|
||||
buildCommandUsage(
|
||||
SUBCMD_LISTEN_ANSWER + " [<source> [<sink> [<interpreters> [<tts> [<stt> [<voice]]]]]]",
|
||||
"Execute a simple dialog sequence without keyword spotting using the default services or the services identified with provided arguments"),
|
||||
buildCommandUsage(SUBCMD_INTERPRETERS, "lists the interpreters"),
|
||||
buildCommandUsage(SUBCMD_KEYWORD_SPOTTERS, "lists the keyword spotters"),
|
||||
@ -140,8 +142,9 @@ public class VoiceConsoleCommandExtension extends AbstractConsoleCommandExtensio
|
||||
TTSService tts = args.length < 5 ? null : voiceManager.getTTS(args[4]);
|
||||
STTService stt = args.length < 6 ? null : voiceManager.getSTT(args[5]);
|
||||
KSService ks = args.length < 7 ? null : voiceManager.getKS(args[6]);
|
||||
String keyword = args.length < 8 ? null : args[7];
|
||||
voiceManager.startDialog(ks, stt, tts, hlis, source, sink, null, keyword, null);
|
||||
Voice voice = args.length < 8 ? null : getVoice(args[7]);
|
||||
String keyword = args.length < 9 ? null : args[8];
|
||||
voiceManager.startDialog(ks, stt, tts, voice, hlis, source, sink, null, keyword, null);
|
||||
} catch (IllegalStateException e) {
|
||||
console.println(Objects.requireNonNullElse(e.getMessage(),
|
||||
"An error occurred while starting the dialog"));
|
||||
@ -163,7 +166,8 @@ public class VoiceConsoleCommandExtension extends AbstractConsoleCommandExtensio
|
||||
: voiceManager.getHLIsByIds(args[3]);
|
||||
TTSService tts = args.length < 5 ? null : voiceManager.getTTS(args[4]);
|
||||
STTService stt = args.length < 6 ? null : voiceManager.getSTT(args[5]);
|
||||
voiceManager.listenAndAnswer(stt, tts, hlis, source, sink, null, null);
|
||||
Voice voice = args.length < 7 ? null : getVoice(args[6]);
|
||||
voiceManager.listenAndAnswer(stt, tts, voice, hlis, source, sink, null, null);
|
||||
} catch (IllegalStateException e) {
|
||||
console.println(Objects.requireNonNullElse(e.getMessage(),
|
||||
"An error occurred while executing the simple dialog sequence"));
|
||||
@ -297,4 +301,8 @@ public class VoiceConsoleCommandExtension extends AbstractConsoleCommandExtensio
|
||||
console.println("No Text-to-Speech services found.");
|
||||
}
|
||||
}
|
||||
|
||||
private @Nullable Voice getVoice(String id) {
|
||||
return voiceManager.getAllVoices().stream().filter(voice -> voice.getUID().equals(id)).findAny().orElse(null);
|
||||
}
|
||||
}
|
||||
|
@ -499,7 +499,7 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider {
|
||||
|
||||
@Override
|
||||
public void startDialog() throws IllegalStateException {
|
||||
startDialog(null, null, null, List.of(), null, null, null, this.keyword, this.listeningItem);
|
||||
startDialog(null, null, null, null, List.of(), null, null, null, this.keyword, this.listeningItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -507,18 +507,20 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider {
|
||||
@Nullable HumanLanguageInterpreter hli, @Nullable AudioSource source, @Nullable AudioSink sink,
|
||||
@Nullable Locale locale, @Nullable String keyword, @Nullable String listeningItem)
|
||||
throws IllegalStateException {
|
||||
startDialog(ks, stt, tts, hli == null ? List.of() : List.of(hli), source, sink, locale, keyword, listeningItem);
|
||||
startDialog(ks, stt, tts, null, hli == null ? List.of() : List.of(hli), source, sink, locale, keyword,
|
||||
listeningItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startDialog(@Nullable KSService ks, @Nullable STTService stt, @Nullable TTSService tts,
|
||||
List<HumanLanguageInterpreter> hlis, @Nullable AudioSource source, @Nullable AudioSink sink,
|
||||
@Nullable Locale locale, @Nullable String keyword, @Nullable String listeningItem)
|
||||
@Nullable Voice voice, List<HumanLanguageInterpreter> hlis, @Nullable AudioSource source,
|
||||
@Nullable AudioSink sink, @Nullable Locale locale, @Nullable String keyword, @Nullable String listeningItem)
|
||||
throws IllegalStateException {
|
||||
// use defaults, if null
|
||||
KSService ksService = (ks == null) ? getKS() : ks;
|
||||
STTService sttService = (stt == null) ? getSTT() : stt;
|
||||
TTSService ttsService = (tts == null) ? getTTS() : tts;
|
||||
Voice prefVoice = voice == null ? getDefaultVoice() : voice;
|
||||
List<HumanLanguageInterpreter> interpreters = hlis;
|
||||
if (interpreters.isEmpty()) {
|
||||
HumanLanguageInterpreter hli = getHLI();
|
||||
@ -545,8 +547,8 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider {
|
||||
if (processor == null) {
|
||||
logger.debug("Starting a new dialog for source {} ({})", audioSource.getLabel(null),
|
||||
audioSource.getId());
|
||||
processor = new DialogProcessor(ksService, sttService, ttsService, interpreters, audioSource, audioSink,
|
||||
loc, kw, item, this.eventPublisher, this.i18nProvider, b);
|
||||
processor = new DialogProcessor(ksService, sttService, ttsService, prefVoice, interpreters, audioSource,
|
||||
audioSink, loc, kw, item, this.eventPublisher, this.i18nProvider, b);
|
||||
dialogProcessors.put(audioSource.getId(), processor);
|
||||
processor.start();
|
||||
} else {
|
||||
@ -584,16 +586,17 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider {
|
||||
|
||||
@Override
|
||||
public void listenAndAnswer() throws IllegalStateException {
|
||||
listenAndAnswer(null, null, List.of(), null, null, null, null);
|
||||
listenAndAnswer(null, null, null, List.of(), null, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listenAndAnswer(@Nullable STTService stt, @Nullable TTSService tts, List<HumanLanguageInterpreter> hlis,
|
||||
@Nullable AudioSource source, @Nullable AudioSink sink, @Nullable Locale locale,
|
||||
@Nullable String listeningItem) throws IllegalStateException {
|
||||
public void listenAndAnswer(@Nullable STTService stt, @Nullable TTSService tts, @Nullable Voice voice,
|
||||
List<HumanLanguageInterpreter> hlis, @Nullable AudioSource source, @Nullable AudioSink sink,
|
||||
@Nullable Locale locale, @Nullable String listeningItem) throws IllegalStateException {
|
||||
// use defaults, if null
|
||||
STTService sttService = (stt == null) ? getSTT() : stt;
|
||||
TTSService ttsService = (tts == null) ? getTTS() : tts;
|
||||
Voice prefVoice = voice == null ? getDefaultVoice() : voice;
|
||||
List<HumanLanguageInterpreter> interpreters = hlis;
|
||||
if (interpreters.isEmpty()) {
|
||||
HumanLanguageInterpreter hli = getHLI();
|
||||
@ -619,8 +622,8 @@ public class VoiceManagerImpl implements VoiceManager, ConfigOptionProvider {
|
||||
if (processor == null) {
|
||||
logger.debug("Executing a simple dialog for source {} ({})", audioSource.getLabel(null),
|
||||
audioSource.getId());
|
||||
processor = new DialogProcessor(sttService, ttsService, interpreters, audioSource, audioSink, loc, item,
|
||||
this.eventPublisher, this.i18nProvider, b);
|
||||
processor = new DialogProcessor(sttService, ttsService, prefVoice, interpreters, audioSource, audioSink,
|
||||
loc, item, this.eventPublisher, this.i18nProvider, b);
|
||||
processor.start();
|
||||
} else {
|
||||
throw new IllegalStateException(String.format(
|
||||
|
@ -14,11 +14,7 @@ package org.openhab.core.voice.internal;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@ -187,7 +183,7 @@ public class VoiceManagerImplTest extends JavaOSGiTest {
|
||||
ksService = new KSServiceStub();
|
||||
hliStub = new HumanLanguageInterpreterStub();
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> voiceManager.startDialog(ksService, sttService, null,
|
||||
assertThrows(IllegalStateException.class, () -> voiceManager.startDialog(ksService, sttService, null, null,
|
||||
List.of(hliStub), source, sink, Locale.ENGLISH, "word", null));
|
||||
|
||||
assertFalse(ksService.isWordSpotted());
|
||||
@ -206,7 +202,7 @@ public class VoiceManagerImplTest extends JavaOSGiTest {
|
||||
registerService(hliStub);
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> voiceManager.startDialog(ksService, sttService, ttsService,
|
||||
List.of(hliStub), source, sink, Locale.FRENCH, "mot", null));
|
||||
null, List.of(hliStub), source, sink, Locale.FRENCH, "mot", null));
|
||||
|
||||
assertFalse(ksService.isWordSpotted());
|
||||
assertFalse(sink.getIsStreamProcessed());
|
||||
@ -223,8 +219,8 @@ public class VoiceManagerImplTest extends JavaOSGiTest {
|
||||
registerService(ttsService);
|
||||
registerService(hliStub);
|
||||
|
||||
voiceManager.startDialog(ksService, sttService, ttsService, List.of(hliStub), source, sink, Locale.ENGLISH,
|
||||
"word", null);
|
||||
voiceManager.startDialog(ksService, sttService, ttsService, null, List.of(hliStub), source, sink,
|
||||
Locale.ENGLISH, "word", null);
|
||||
|
||||
assertTrue(ksService.isWordSpotted());
|
||||
assertTrue(sttService.isRecognized());
|
||||
@ -251,8 +247,8 @@ public class VoiceManagerImplTest extends JavaOSGiTest {
|
||||
|
||||
ksService.setExceptionExpected(true);
|
||||
|
||||
voiceManager.startDialog(ksService, sttService, ttsService, List.of(hliStub), source, sink, Locale.ENGLISH, "",
|
||||
null);
|
||||
voiceManager.startDialog(ksService, sttService, ttsService, null, List.of(hliStub), source, sink,
|
||||
Locale.ENGLISH, "", null);
|
||||
|
||||
assertFalse(ksService.isWordSpotted());
|
||||
assertFalse(sttService.isRecognized());
|
||||
@ -277,8 +273,8 @@ public class VoiceManagerImplTest extends JavaOSGiTest {
|
||||
|
||||
ksService.setErrorExpected(true);
|
||||
|
||||
voiceManager.startDialog(ksService, sttService, ttsService, List.of(hliStub), source, sink, Locale.ENGLISH,
|
||||
"word", null);
|
||||
voiceManager.startDialog(ksService, sttService, ttsService, null, List.of(hliStub), source, sink,
|
||||
Locale.ENGLISH, "word", null);
|
||||
|
||||
assertFalse(ksService.isWordSpotted());
|
||||
assertFalse(sttService.isRecognized());
|
||||
@ -304,8 +300,8 @@ public class VoiceManagerImplTest extends JavaOSGiTest {
|
||||
|
||||
sttService.setExceptionExpected(true);
|
||||
|
||||
voiceManager.startDialog(ksService, sttService, ttsService, List.of(hliStub), source, sink, Locale.ENGLISH,
|
||||
"word", null);
|
||||
voiceManager.startDialog(ksService, sttService, ttsService, null, List.of(hliStub), source, sink,
|
||||
Locale.ENGLISH, "word", null);
|
||||
|
||||
assertTrue(ksService.isWordSpotted());
|
||||
assertFalse(sttService.isRecognized());
|
||||
@ -330,8 +326,8 @@ public class VoiceManagerImplTest extends JavaOSGiTest {
|
||||
|
||||
sttService.setErrorExpected(true);
|
||||
|
||||
voiceManager.startDialog(ksService, sttService, ttsService, List.of(hliStub), source, sink, Locale.ENGLISH,
|
||||
"word", null);
|
||||
voiceManager.startDialog(ksService, sttService, ttsService, null, List.of(hliStub), source, sink,
|
||||
Locale.ENGLISH, "word", null);
|
||||
|
||||
assertTrue(ksService.isWordSpotted());
|
||||
assertFalse(sttService.isRecognized());
|
||||
@ -356,8 +352,8 @@ public class VoiceManagerImplTest extends JavaOSGiTest {
|
||||
|
||||
hliStub.setExceptionExpected(true);
|
||||
|
||||
voiceManager.startDialog(ksService, sttService, ttsService, List.of(hliStub), source, sink, Locale.ENGLISH,
|
||||
"word", null);
|
||||
voiceManager.startDialog(ksService, sttService, ttsService, null, List.of(hliStub), source, sink,
|
||||
Locale.ENGLISH, "word", null);
|
||||
|
||||
assertTrue(ksService.isWordSpotted());
|
||||
assertTrue(sttService.isRecognized());
|
||||
@ -419,13 +415,13 @@ public class VoiceManagerImplTest extends JavaOSGiTest {
|
||||
registerService(ttsService);
|
||||
registerService(hliStub);
|
||||
|
||||
voiceManager.startDialog(ksService, sttService, ttsService, List.of(hliStub), source, sink, Locale.ENGLISH,
|
||||
"word", null);
|
||||
voiceManager.startDialog(ksService, sttService, ttsService, null, List.of(hliStub), source, sink,
|
||||
Locale.ENGLISH, "word", null);
|
||||
|
||||
assertTrue(ksService.isWordSpotted());
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> voiceManager.startDialog(ksService, sttService, ttsService,
|
||||
List.of(hliStub), source, sink, Locale.ENGLISH, "word", null));
|
||||
null, List.of(hliStub), source, sink, Locale.ENGLISH, "word", null));
|
||||
|
||||
voiceManager.stopDialog(source);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user