Search in sources :

Example 6 with AudioSink

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);
}
Also used : UpnpNotificationAudioSink(org.openhab.binding.upnpcontrol.internal.audiosink.UpnpNotificationAudioSink) AudioSink(org.openhab.core.audio.AudioSink) UpnpAudioSink(org.openhab.binding.upnpcontrol.internal.audiosink.UpnpAudioSink) UpnpHandler(org.openhab.binding.upnpcontrol.internal.handler.UpnpHandler)

Example 7 with AudioSink

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.");
    }
}
Also used : AudioSink(org.openhab.core.audio.AudioSink) Locale(java.util.Locale)

Example 8 with AudioSink

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();
}
Also used : Locale(java.util.Locale) AudioSink(org.openhab.core.audio.AudioSink) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Example 9 with AudioSink

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());
    }
}
Also used : AudioSource(org.openhab.core.audio.AudioSource) AudioSink(org.openhab.core.audio.AudioSink) Locale(java.util.Locale) STTService(org.openhab.core.voice.STTService) KSService(org.openhab.core.voice.KSService) TTSService(org.openhab.core.voice.TTSService) HumanLanguageInterpreter(org.openhab.core.voice.text.HumanLanguageInterpreter) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Operation(io.swagger.v3.oas.annotations.Operation)

Example 10 with AudioSink

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)));
        }
    }
}
Also used : AudioSource(org.openhab.core.audio.AudioSource) AudioSink(org.openhab.core.audio.AudioSink) Locale(java.util.Locale) STTService(org.openhab.core.voice.STTService) Bundle(org.osgi.framework.Bundle) KSService(org.openhab.core.voice.KSService) TTSService(org.openhab.core.voice.TTSService) HumanLanguageInterpreter(org.openhab.core.voice.text.HumanLanguageInterpreter)

Aggregations

AudioSink (org.openhab.core.audio.AudioSink)19 Locale (java.util.Locale)8 ServiceRegistration (org.osgi.framework.ServiceRegistration)8 Hashtable (java.util.Hashtable)6 AudioSource (org.openhab.core.audio.AudioSource)6 KSService (org.openhab.core.voice.KSService)5 STTService (org.openhab.core.voice.STTService)5 TTSService (org.openhab.core.voice.TTSService)5 HumanLanguageInterpreter (org.openhab.core.voice.text.HumanLanguageInterpreter)5 Nullable (org.eclipse.jdt.annotation.Nullable)4 Operation (io.swagger.v3.oas.annotations.Operation)3 Path (javax.ws.rs.Path)3 ThingTypeUID (org.openhab.core.thing.ThingTypeUID)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 PulseAudioAudioSink (org.openhab.binding.pulseaudio.internal.PulseAudioAudioSink)2 SqueezeBoxPlayerHandler (org.openhab.binding.squeezebox.internal.handler.SqueezeBoxPlayerHandler)2 SqueezeBoxServerHandler (org.openhab.binding.squeezebox.internal.handler.SqueezeBoxServerHandler)2