Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Feature: add annotations to speech events
Browse files Browse the repository at this point in the history
  • Loading branch information
space-pope committed Jul 24, 2020
1 parent 083d527 commit 68d3988
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 15 deletions.
14 changes: 10 additions & 4 deletions src/main/java/io/spokestack/spokestack/OnSpeechEventListener.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package io.spokestack.spokestack;

import androidx.annotation.NonNull;

/**
* speech event callback interface.
*
* This is the primary event interface in Spokestack. The speech pipeline
* routes events/errors asynchronously through it as they occur.
* <p>
* This is the primary event interface in Spokestack. The speech pipeline routes
* events/errors asynchronously through it as they occur.
* </p>
*/
public interface OnSpeechEventListener {
/**
* receives a speech event.
*
* @param event the name of the event that was raised
* @param context the current speech context
* @throws Exception on error
*/
void onEvent(SpeechContext.Event event, SpeechContext context)
throws Exception;
void onEvent(@NonNull SpeechContext.Event event,
@NonNull SpeechContext context)
throws Exception;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.spokestack.spokestack;

import androidx.annotation.NonNull;
import io.spokestack.spokestack.tensorflow.TensorflowModel;
import io.spokestack.spokestack.wakeword.WakewordTrigger;
import io.spokestack.spokestack.wakeword.WakewordTriggerTest;
Expand Down Expand Up @@ -102,7 +103,7 @@ public void close() {
this.timeout.close();
}

public void onEvent(SpeechContext.Event event, SpeechContext context) {
public void onEvent(@NonNull SpeechContext.Event event, @NonNull SpeechContext context) {
this.event = event;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/io/spokestack/spokestack/SpeechContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.*;
import java.nio.ByteBuffer;

import androidx.annotation.NonNull;
import io.spokestack.spokestack.util.EventTracer;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -123,7 +124,8 @@ public void testDispatch() {
// listener error
context.addOnSpeechEventListener(this);
context.addOnSpeechEventListener(new OnSpeechEventListener() {
public void onEvent(Event event, SpeechContext context)
public void onEvent(@NonNull Event event,
@NonNull SpeechContext context)
throws Exception{
throw new Exception("failed");
}
Expand Down Expand Up @@ -213,7 +215,7 @@ public void testActivationEvents() {
assertNull(this.event);
}

public void onEvent(Event event, SpeechContext context) {
public void onEvent(@NonNull Event event, @NonNull SpeechContext context) {
this.event = event;
this.context = context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.concurrent.Semaphore;
import java.nio.ByteBuffer;

import androidx.annotation.NonNull;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.function.Executable;
Expand Down Expand Up @@ -221,7 +222,8 @@ private void transact(boolean managed) throws Exception {
}
}

public void onEvent(SpeechContext.Event event, SpeechContext context) {
public void onEvent(@NonNull SpeechContext.Event event,
@NonNull SpeechContext context) {
this.events.add(event);
}

Expand Down Expand Up @@ -264,7 +266,8 @@ public ManagedInput(SpeechConfig config) {
}

@Override
public void read(SpeechContext context, ByteBuffer frame) throws InterruptedException {
public void read(SpeechContext context, ByteBuffer frame)
throws InterruptedException {
if (!context.isManaged()) {
super.read(context, frame);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.os.Bundle;
import android.speech.RecognitionListener;
import android.speech.SpeechRecognizer;
import androidx.annotation.NonNull;
import io.spokestack.spokestack.OnSpeechEventListener;
import io.spokestack.spokestack.SpeechConfig;
import io.spokestack.spokestack.SpeechContext;
Expand Down Expand Up @@ -191,7 +192,7 @@ public void clear() {
}

@Override
public void onEvent(SpeechContext.Event event, SpeechContext context) {
public void onEvent(@NonNull SpeechContext.Event event, @NonNull SpeechContext context) {
switch (event) {
case RECOGNIZE:
this.transcript = context.getTranscript();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.spokestack.spokestack.asr;

import androidx.annotation.NonNull;
import io.spokestack.spokestack.OnSpeechEventListener;
import io.spokestack.spokestack.SpeechConfig;
import io.spokestack.spokestack.SpeechContext;
Expand Down Expand Up @@ -124,7 +125,8 @@ private SpeechContext createContext(SpeechConfig config) {
return context;
}

public void onEvent(SpeechContext.Event event, SpeechContext context) {
public void onEvent(@NonNull SpeechContext.Event event,
@NonNull SpeechContext context) {
this.event = event;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.*;
import java.nio.ByteBuffer;

import androidx.annotation.NonNull;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -151,7 +152,8 @@ private SpeechContext createContext(SpeechConfig config) {
return context;
}

public void onEvent(SpeechContext.Event event, SpeechContext context) {
public void onEvent(@NonNull SpeechContext.Event event,
@NonNull SpeechContext context) {
this.event = event;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.spokestack.spokestack.microsoft;

import androidx.annotation.NonNull;
import com.microsoft.cognitiveservices.speech.CancellationErrorCode;
import com.microsoft.cognitiveservices.speech.CancellationReason;
import com.microsoft.cognitiveservices.speech.ResultReason;
Expand Down Expand Up @@ -187,7 +188,8 @@ private SpeechContext createContext(SpeechConfig config) {
return context;
}

public void onEvent(SpeechContext.Event event, SpeechContext context) {
public void onEvent(@NonNull SpeechContext.Event event,
@NonNull SpeechContext context) {
this.event = event;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import androidx.annotation.NonNull;
import org.junit.Test;
import org.junit.jupiter.api.function.Executable;
import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -293,7 +294,7 @@ public void process() throws Exception {
this.wake.process(this.context, this.frame);
}

public void onEvent(SpeechContext.Event event, SpeechContext context) {
public void onEvent(@NonNull SpeechContext.Event event, @NonNull SpeechContext context) {
this.event = event;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import java.nio.ByteBuffer;

import androidx.annotation.NonNull;
import org.junit.Test;

import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -53,7 +54,7 @@ private ByteBuffer sampleBuffer(SpeechConfig config) {
return ByteBuffer.allocateDirect(samples * 2);
}

public void onEvent(SpeechContext.Event event, SpeechContext context) {
public void onEvent(@NonNull SpeechContext.Event event, @NonNull SpeechContext context) {
this.event = event;
}
}

0 comments on commit 68d3988

Please sign in to comment.