Search in sources :

Example 1 with HumanLanguageInterpreter

use of org.eclipse.smarthome.core.voice.text.HumanLanguageInterpreter in project smarthome by eclipse.

the class VoiceManagerImpl method startDialog.

@Override
public void startDialog(KSService ksService, STTService sttService, TTSService ttsService, HumanLanguageInterpreter interpreter, AudioSource audioSource, AudioSink audioSink, Locale locale, String keyword, String listeningItem) {
    // use defaults, if null
    KSService ks = (ksService == null) ? getKS() : ksService;
    STTService stt = (sttService == null) ? getSTT() : sttService;
    TTSService tts = (ttsService == null) ? getTTS() : ttsService;
    HumanLanguageInterpreter hli = (interpreter == null) ? getHLI() : interpreter;
    AudioSource source = (audioSource == null) ? audioManager.getSource() : audioSource;
    AudioSink sink = (audioSink == null) ? audioManager.getSink() : audioSink;
    Locale loc = (locale == null) ? localeProvider.getLocale() : locale;
    String kw = (keyword == null) ? this.keyword : keyword;
    String item = (listeningItem == null) ? this.listeningItem : listeningItem;
    if (ks != null && stt != null && tts != null && hli != null && source != null && sink != null && loc != null && kw != null) {
        DialogProcessor processor = new DialogProcessor(ks, stt, tts, hli, source, sink, loc, kw, item, this.eventPublisher);
        processor.start();
    } else {
        String msg = "Cannot start dialog as services are missing.";
        logger.error(msg);
        throw new IllegalStateException(msg);
    }
}
Also used : AudioSource(org.eclipse.smarthome.core.audio.AudioSource) AudioSink(org.eclipse.smarthome.core.audio.AudioSink) Locale(java.util.Locale) STTService(org.eclipse.smarthome.core.voice.STTService) KSService(org.eclipse.smarthome.core.voice.KSService) TTSService(org.eclipse.smarthome.core.voice.TTSService) HumanLanguageInterpreter(org.eclipse.smarthome.core.voice.text.HumanLanguageInterpreter)

Example 2 with HumanLanguageInterpreter

use of org.eclipse.smarthome.core.voice.text.HumanLanguageInterpreter in project smarthome by eclipse.

the class VoiceResource method interpret.

@POST
@Path("/interpreters/{id: [a-zA-Z_0-9]*}")
@Consumes(MediaType.TEXT_PLAIN)
@ApiOperation(value = "Sends a text to a given human language interpreter.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 404, message = "No human language interpreter was found."), @ApiResponse(code = 400, message = "interpretation exception occurs") })
public Response interpret(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language, @ApiParam(value = "text to interpret", required = true) String text, @PathParam("id") @ApiParam(value = "interpreter id", required = true) String id) {
    final Locale locale = LocaleUtil.getLocale(language);
    HumanLanguageInterpreter hli = voiceManager.getHLI(id);
    if (hli != null) {
        try {
            hli.interpret(locale, text);
            return Response.ok(null, MediaType.TEXT_PLAIN).build();
        } catch (InterpretationException e) {
            return JSONResponse.createErrorResponse(Status.BAD_REQUEST, e.getMessage());
        }
    } else {
        return JSONResponse.createErrorResponse(Status.NOT_FOUND, "Interpreter not found");
    }
}
Also used : Locale(java.util.Locale) InterpretationException(org.eclipse.smarthome.core.voice.text.InterpretationException) HumanLanguageInterpreter(org.eclipse.smarthome.core.voice.text.HumanLanguageInterpreter) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with HumanLanguageInterpreter

use of org.eclipse.smarthome.core.voice.text.HumanLanguageInterpreter in project smarthome by eclipse.

the class VoiceResource method getInterpreters.

@GET
@Path("/interpreters")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get the list of all interpreters.", response = HumanLanguageInterpreterDTO.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK") })
public Response getInterpreters(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language) {
    final Locale locale = LocaleUtil.getLocale(language);
    Collection<HumanLanguageInterpreter> hlis = voiceManager.getHLIs();
    List<HumanLanguageInterpreterDTO> dtos = new ArrayList<>(hlis.size());
    for (HumanLanguageInterpreter hli : hlis) {
        dtos.add(HLIMapper.map(hli, locale));
    }
    return Response.ok(dtos).build();
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) HumanLanguageInterpreter(org.eclipse.smarthome.core.voice.text.HumanLanguageInterpreter) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with HumanLanguageInterpreter

use of org.eclipse.smarthome.core.voice.text.HumanLanguageInterpreter in project smarthome by eclipse.

the class VoiceManagerImpl method getParameterOptions.

@Override
public Collection<ParameterOption> getParameterOptions(URI uri, String param, Locale locale) {
    if (uri.toString().equals(CONFIG_URI)) {
        if (CONFIG_DEFAULT_HLI.equals(param)) {
            List<ParameterOption> options = new ArrayList<>();
            for (HumanLanguageInterpreter hli : humanLanguageInterpreters.values()) {
                ParameterOption option = new ParameterOption(hli.getId(), hli.getLabel(locale));
                options.add(option);
            }
            return options;
        } else if (CONFIG_DEFAULT_KS.equals(param)) {
            List<ParameterOption> options = new ArrayList<>();
            for (KSService ks : ksServices.values()) {
                ParameterOption option = new ParameterOption(ks.getId(), ks.getLabel(locale));
                options.add(option);
            }
            return options;
        } else if (CONFIG_DEFAULT_STT.equals(param)) {
            List<ParameterOption> options = new ArrayList<>();
            for (STTService stt : sttServices.values()) {
                ParameterOption option = new ParameterOption(stt.getId(), stt.getLabel(locale));
                options.add(option);
            }
            return options;
        } else if (CONFIG_DEFAULT_TTS.equals(param)) {
            List<ParameterOption> options = new ArrayList<>();
            for (TTSService tts : ttsServices.values()) {
                ParameterOption option = new ParameterOption(tts.getId(), tts.getLabel(locale));
                options.add(option);
            }
            return options;
        } else if (CONFIG_DEFAULT_VOICE.equals(param)) {
            List<ParameterOption> options = new ArrayList<>();
            for (Voice voice : getAllVoices()) {
                ParameterOption option = new ParameterOption(voice.getUID(), voice.getLabel() + " - " + voice.getLocale().getDisplayName());
                options.add(option);
            }
            return options;
        }
    }
    return null;
}
Also used : STTService(org.eclipse.smarthome.core.voice.STTService) ParameterOption(org.eclipse.smarthome.config.core.ParameterOption) KSService(org.eclipse.smarthome.core.voice.KSService) ArrayList(java.util.ArrayList) HumanLanguageInterpreter(org.eclipse.smarthome.core.voice.text.HumanLanguageInterpreter) TTSService(org.eclipse.smarthome.core.voice.TTSService) ArrayList(java.util.ArrayList) List(java.util.List) Voice(org.eclipse.smarthome.core.voice.Voice)

Example 5 with HumanLanguageInterpreter

use of org.eclipse.smarthome.core.voice.text.HumanLanguageInterpreter in project smarthome by eclipse.

the class VoiceResource method getInterpreter.

@GET
@Path("/interpreters/{id: [a-zA-Z_0-9]*}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets a single interpreters.", response = HumanLanguageInterpreterDTO.class)
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 404, message = "Interpreter not found") })
public Response getInterpreter(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language, @PathParam("id") @ApiParam(value = "interpreter id", required = true) String id) {
    final Locale locale = LocaleUtil.getLocale(language);
    HumanLanguageInterpreter hli = voiceManager.getHLI(id);
    if (hli != null) {
        HumanLanguageInterpreterDTO dto = HLIMapper.map(hli, locale);
        return Response.ok(dto).build();
    } else {
        return JSONResponse.createErrorResponse(Status.NOT_FOUND, "Interpreter not found");
    }
}
Also used : Locale(java.util.Locale) HumanLanguageInterpreter(org.eclipse.smarthome.core.voice.text.HumanLanguageInterpreter) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

HumanLanguageInterpreter (org.eclipse.smarthome.core.voice.text.HumanLanguageInterpreter)5 Locale (java.util.Locale)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Path (javax.ws.rs.Path)3 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 KSService (org.eclipse.smarthome.core.voice.KSService)2 STTService (org.eclipse.smarthome.core.voice.STTService)2 TTSService (org.eclipse.smarthome.core.voice.TTSService)2 List (java.util.List)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 ParameterOption (org.eclipse.smarthome.config.core.ParameterOption)1 AudioSink (org.eclipse.smarthome.core.audio.AudioSink)1 AudioSource (org.eclipse.smarthome.core.audio.AudioSource)1 Voice (org.eclipse.smarthome.core.voice.Voice)1 InterpretationException (org.eclipse.smarthome.core.voice.text.InterpretationException)1