mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 21:31:53 +01:00
[voice] Add interface to represent a remote keyword spotter (#3564)
Signed-off-by: Miguel Álvarez <miguelwork92@gmail.com>
This commit is contained in:
parent
c8a6cf2603
commit
4ace1557f4
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright (c) 2010-2023 Contributors to the openHAB project
|
||||
*
|
||||
* See the NOTICE file(s) distributed with this work for additional
|
||||
* information.
|
||||
*
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.openhab.core.voice;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.openhab.core.audio.AudioStream;
|
||||
|
||||
/**
|
||||
* This is the interface that an edge keyword spotting service has to implement.
|
||||
* Used to register a keyword spotting service that is running on a remote device.
|
||||
*
|
||||
* @author Miguel Álvarez - Initial contribution
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public interface KSEdgeService extends KSService {
|
||||
|
||||
/**
|
||||
* This method links the remote keyword spotting process to a consumer.
|
||||
*
|
||||
* The method is supposed to return fast.
|
||||
*
|
||||
* @param ksListener Non-null {@link KSListener} that {@link KSEvent} events target
|
||||
* @throws KSException if any parameter is invalid or a problem occurs
|
||||
*/
|
||||
KSServiceHandle spot(KSListener ksListener) throws KSException;
|
||||
|
||||
@Override
|
||||
default KSServiceHandle spot(KSListener ksListener, AudioStream audioStream, Locale locale, String keyword)
|
||||
throws KSException {
|
||||
throw new KSException("An edge keyword spotter is not meant to process audio in the server");
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@ import org.openhab.core.items.ItemUtil;
|
||||
import org.openhab.core.items.events.ItemEventFactory;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
import org.openhab.core.voice.DialogContext;
|
||||
import org.openhab.core.voice.KSEdgeService;
|
||||
import org.openhab.core.voice.KSErrorEvent;
|
||||
import org.openhab.core.voice.KSEvent;
|
||||
import org.openhab.core.voice.KSException;
|
||||
@ -164,9 +165,13 @@ public class DialogProcessor implements KSListener, STTListener {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
AudioStream stream = dialogContext.source().getInputStream(fmt);
|
||||
streamKS = stream;
|
||||
ksServiceHandle = ksService.spot(this, stream, dialogContext.locale(), keyword);
|
||||
if (ksService instanceof KSEdgeService) {
|
||||
((KSEdgeService) ksService).spot(this);
|
||||
} else {
|
||||
AudioStream stream = dialogContext.source().getInputStream(fmt);
|
||||
streamKS = stream;
|
||||
ksServiceHandle = ksService.spot(this, stream, dialogContext.locale(), keyword);
|
||||
}
|
||||
playStartSound();
|
||||
} catch (AudioException e) {
|
||||
logger.warn("Encountered audio error: {}", e.getMessage());
|
||||
|
Loading…
Reference in New Issue
Block a user