[runtime/android] refine android demo, use hey_snips as the default wakeup word (#90)

This commit is contained in:
Binbin Zhang 2022-09-12 21:55:06 +08:00 committed by GitHub
parent 4bacb81f7f
commit ff5dcf29ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 24 deletions

Binary file not shown.

View File

@ -62,14 +62,12 @@ void spot_thread_func() {
feature_pipeline->Read(80, &feats);
std::vector<std::vector<float>> prob;
spotter->Forward(feats, &prob);
float max_hi_xiaowen = 0;
float max_nihao_wenwen = 0;
float max_prob = 0.0;
for (int t = 0; t < prob.size(); t++) {
max_hi_xiaowen = std::max(prob[t][0], max_hi_xiaowen);
max_nihao_wenwen = std::max(prob[t][1], max_nihao_wenwen);
for (int j = 0; j < prob[t].size(); j++) {
max_prob = std::max(prob[t][j], max_prob);
}
}
float max_prob = max_hi_xiaowen + max_nihao_wenwen;
result = std::to_string(offset) + " prob: " + std::to_string(max_prob);
offset += prob.size();
}

View File

@ -35,6 +35,7 @@ public class MainActivity extends AppCompatActivity {
private static final int SAMPLE_RATE = 16000; // The sampling rate
private static final int MAX_QUEUE_SIZE = 2500; // 100 seconds audio, 1 / 0.04 * 100
private static final List<String> resource = Arrays.asList("kws.ort");
private static final String HINTS = "say \"Hey Snips\" to wakeup";
private boolean startRecord = false;
private AudioRecord record = null;
@ -91,7 +92,7 @@ public class MainActivity extends AppCompatActivity {
}
TextView textView = findViewById(R.id.textView);
textView.setText("");
textView.setText(HINTS);
Spot.init(getFilesDir().getPath());
Button button = findViewById(R.id.button);
@ -209,4 +210,4 @@ public class MainActivity extends AppCompatActivity {
}
}).start();
}
}
}

View File

@ -1,27 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:VoiceRect="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:VoiceRect="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAlignment="center"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#F4F4F4"
android:maxLines="15"
android:minLines="15"
android:text="TextView"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.08" />
android:layout_marginTop="350dp"
android:textAlignment="center"
android:textSize="20sp"
VoiceRect:layout_constraintEnd_toEndOf="parent"
VoiceRect:layout_constraintStart_toStartOf="parent"
VoiceRect:layout_constraintTop_toTopOf="parent" />
<cn.org.wenet.wekws.VoiceRectView
android:id="@+id/voiceRectView"
@ -34,8 +30,7 @@
VoiceRect:RectTopColor="@color/green"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/button"
@ -47,4 +42,6 @@
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>