use of org.openhab.core.audio.AudioSink in project openhab-addons by openhab.
the class UpnpControlHandlerFactory method removeRenderer.
private void removeRenderer(String key) {
UpnpHandler handler = upnpServers.get(key);
if (handler == null) {
return;
}
logger.debug("Removing media renderer handler for {} with UID {}", handler.getThing().getLabel(), handler.getThing().getUID());
if (audioSinkRegistrations.containsKey(key)) {
logger.debug("Removing audio sink registration for {}", handler.getThing().getLabel());
ServiceRegistration<AudioSink> reg = audioSinkRegistrations.get(key);
if (reg != null) {
reg.unregister();
}
audioSinkRegistrations.remove(key);
}
String notificationKey = key + NOTIFICATION_AUDIOSINK_EXTENSION;
if (audioSinkRegistrations.containsKey(notificationKey)) {
logger.debug("Removing notification audio sink registration for {}", handler.getThing().getLabel());
ServiceRegistration<AudioSink> reg = audioSinkRegistrations.get(notificationKey);
if (reg != null) {
reg.unregister();
}
audioSinkRegistrations.remove(notificationKey);
}
upnpServers.forEach((thingId, value) -> value.removeRendererOption(key));
handlers.remove(handler.getUDN());
upnpRenderers.remove(key);
}
use of org.openhab.core.audio.AudioSink in project openhab-core by openhab.
the class AudioConsoleCommandExtension method listSinks.
private void listSinks(Console console) {
Set<AudioSink> sinks = audioManager.getAllSinks();
if (!sinks.isEmpty()) {
AudioSink defaultSink = audioManager.getSink();
Locale locale = localeProvider.getLocale();
sinks.stream().sorted(comparing(s -> s.getLabel(locale))).forEach(sink -> {
console.println(String.format("%s %s (%s)", sink.equals(defaultSink) ? "*" : " ", sink.getLabel(locale), sink.getId()));
});
} else {
console.println("No audio sinks found.");
}
}
use of org.openhab.core.audio.AudioSink in project openhab-core by openhab.
the class AudioResource method getSinks.
@GET
@Path("/sinks")
@Produces(MediaType.APPLICATION_JSON)
@Operation(operationId = "getAudioSinks", summary = "Get the list of all sinks.", responses = { @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = AudioSinkDTO.class)))) })
public Response getSinks(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language) {
final Locale locale = localeService.getLocale(language);
Collection<AudioSink> sinks = audioManager.getAllSinks();
List<AudioSinkDTO> dtos = new ArrayList<>(sinks.size());
for (AudioSink sink : sinks) {
dtos.add(AudioMapper.map(sink, locale));
}
return Response.ok(dtos).build();
}
use of org.openhab.core.audio.AudioSink in project openhab-core by openhab.
the class VoiceResource method startDialog.
@POST
@Path("/dialog/start")
@Consumes(MediaType.TEXT_PLAIN)
@Operation(operationId = "startDialog", summary = "Start dialog processing for a given audio source.", responses = { @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "One of the given ids is wrong."), @ApiResponse(responseCode = "400", description = "Services are missing or language is not supported by services or dialog processing is already started for the audio source.") })
public Response startDialog(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language, @QueryParam("sourceId") @Parameter(description = "source ID") @Nullable String sourceId, @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("hliId") @Parameter(description = "interpreter ID") @Nullable String hliId, @QueryParam("sinkId") @Parameter(description = "audio sink ID") @Nullable String sinkId, @QueryParam("keyword") @Parameter(description = "keyword") @Nullable String keyword, @QueryParam("listeningItem") @Parameter(description = "listening item") @Nullable String listeningItem) {
AudioSource source = null;
if (sourceId != null) {
source = audioManager.getSource(sourceId);
if (source == null) {
return JSONResponse.createErrorResponse(Status.NOT_FOUND, "Audio source not found");
}
}
KSService ks = null;
if (ksId != null) {
ks = voiceManager.getKS(ksId);
if (ks == null) {
return JSONResponse.createErrorResponse(Status.NOT_FOUND, "Keyword spotter not found");
}
}
STTService stt = null;
if (sttId != null) {
stt = voiceManager.getSTT(sttId);
if (stt == null) {
return JSONResponse.createErrorResponse(Status.NOT_FOUND, "Speech-to-Text not found");
}
}
TTSService tts = null;
if (ttsId != null) {
tts = voiceManager.getTTS(ttsId);
if (tts == null) {
return JSONResponse.createErrorResponse(Status.NOT_FOUND, "Text-to-Speech not found");
}
}
HumanLanguageInterpreter hli = null;
if (hliId != null) {
hli = voiceManager.getHLI(hliId);
if (hli == null) {
return JSONResponse.createErrorResponse(Status.NOT_FOUND, "Interpreter not found");
}
}
AudioSink sink = null;
if (sinkId != null) {
sink = audioManager.getSink(sinkId);
if (sink == null) {
return JSONResponse.createErrorResponse(Status.NOT_FOUND, "Audio sink not found");
}
}
final Locale locale = localeService.getLocale(language);
try {
voiceManager.startDialog(ks, stt, tts, hli, source, sink, locale, keyword, listeningItem);
return Response.ok(null, MediaType.TEXT_PLAIN).build();
} catch (IllegalStateException e) {
return JSONResponse.createErrorResponse(Status.BAD_REQUEST, e.getMessage());
}
}
use of org.openhab.core.audio.AudioSink in project openhab-core by openhab.
the class VoiceManagerImpl method startDialog.
@Override
public void startDialog(@Nullable KSService ks, @Nullable STTService stt, @Nullable TTSService tts, @Nullable HumanLanguageInterpreter hli, @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;
HumanLanguageInterpreter interpreter = (hli == null) ? getHLI() : hli;
AudioSource audioSource = (source == null) ? audioManager.getSource() : source;
AudioSink audioSink = (sink == null) ? audioManager.getSink() : sink;
Locale loc = (locale == null) ? localeProvider.getLocale() : locale;
String kw = (keyword == null) ? this.keyword : keyword;
String item = (listeningItem == null) ? this.listeningItem : listeningItem;
Bundle b = bundle;
if (ksService == null || sttService == null || ttsService == null || interpreter == null || audioSource == null || audioSink == null || b == null) {
throw new IllegalStateException("Cannot start dialog as services are missing.");
} else if (!checkLocales(ksService.getSupportedLocales(), loc) || !checkLocales(sttService.getSupportedLocales(), loc) || !checkLocales(interpreter.getSupportedLocales(), loc)) {
throw new IllegalStateException("Cannot start dialog as provided locale is not supported by all services.");
} else {
DialogProcessor processor = dialogProcessors.get(audioSource.getId());
if (processor == null) {
logger.debug("Starting a new dialog for source {} ({})", audioSource.getLabel(null), audioSource.getId());
processor = new DialogProcessor(ksService, sttService, ttsService, interpreter, audioSource, audioSink, loc, kw, item, this.eventPublisher, this.i18nProvider, b);
dialogProcessors.put(audioSource.getId(), processor);
processor.start();
} else {
throw new IllegalStateException(String.format("Cannot start dialog as a dialog is already started for audio source '%s'.", audioSource.getLabel(null)));
}
}
}
Aggregations