From 88fc9834b1aa72a6dd169a3916f24b15e686002c Mon Sep 17 00:00:00 2001 From: pengzhendong <275331498@qq.com> Date: Sat, 3 Sep 2022 16:32:22 +0800 Subject: [PATCH] [android] add voice rectangle view --- .../android/app/src/main/AndroidManifest.xml | 2 +- .../android/app/src/main/cpp/CMakeLists.txt | 0 runtime/android/app/src/main/cpp/frontend | 1 + runtime/android/app/src/main/cpp/kws | 1 + runtime/android/app/src/main/cpp/utils | 1 + .../cn/org/wenet/wekws/VoiceRectView.java | 136 ++++++++++++++++++ .../android/app/src/main/res/values/attrs.xml | 17 +++ .../app/src/main/res/values/colors.xml | 6 + 8 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 runtime/android/app/src/main/cpp/CMakeLists.txt create mode 120000 runtime/android/app/src/main/cpp/frontend create mode 120000 runtime/android/app/src/main/cpp/kws create mode 120000 runtime/android/app/src/main/cpp/utils create mode 100644 runtime/android/app/src/main/java/cn/org/wenet/wekws/VoiceRectView.java create mode 100644 runtime/android/app/src/main/res/values/attrs.xml diff --git a/runtime/android/app/src/main/AndroidManifest.xml b/runtime/android/app/src/main/AndroidManifest.xml index efb5981..8f25ec3 100644 --- a/runtime/android/app/src/main/AndroidManifest.xml +++ b/runtime/android/app/src/main/AndroidManifest.xml @@ -2,7 +2,7 @@ - + = 0) { + System.arraycopy(mEnergyBuffer, 1, mEnergyBuffer, 0, mEnergyBuffer.length - 1); + } + mEnergyBuffer[mEnergyBuffer.length - 1] = energy; + } + + public void zero() { + Arrays.fill(mEnergyBuffer, 0); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + double mRandom; + float currentHeight; + for (int i = 0; i < mRectCount; i++) { + // 由于只是简单的案例就不监听音频输入,随机模拟一些数字即可 + mRandom = Math.random(); + + //if (i < 1 || i > mRectCount - 2) mRandom = 0; + currentHeight = (float) (mRectHeight * mEnergyBuffer[i]); + + // 矩形的绘制是从左边开始到上、右、下边(左右边距离左边画布边界的距离,上下边距离上边画布边界的距离) + canvas.drawRect( + (float) (mRectWidth * i + offset), + (mRectHeight - currentHeight) / 2, + (float) (mRectWidth * (i + 1)), + mRectHeight / 2 + currentHeight / 2, + mRectPaint + ); + } + // 使得view延迟重绘 + postInvalidateDelayed(mSpeed); + } +} \ No newline at end of file diff --git a/runtime/android/app/src/main/res/values/attrs.xml b/runtime/android/app/src/main/res/values/attrs.xml new file mode 100644 index 0000000..0e2c7da --- /dev/null +++ b/runtime/android/app/src/main/res/values/attrs.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/runtime/android/app/src/main/res/values/colors.xml b/runtime/android/app/src/main/res/values/colors.xml index f8c6127..3a15f9a 100644 --- a/runtime/android/app/src/main/res/values/colors.xml +++ b/runtime/android/app/src/main/res/values/colors.xml @@ -7,4 +7,10 @@ #FF018786 #FF000000 #FFFFFFFF + + #f16d7a + #b7d28d + #b8f1ed + #b7d28d + #b8f1ed \ No newline at end of file