>>>>>> xiaojinchi_branch
diff --git a/src/Notes-master3/app/src/main/java/net/micode/notes/ui/NoteItemData.java b/src/Notes-master3/app/src/main/java/net/micode/notes/ui/NoteItemData.java
index 976920b..67dc8f7 100644
--- a/src/Notes-master3/app/src/main/java/net/micode/notes/ui/NoteItemData.java
+++ b/src/Notes-master3/app/src/main/java/net/micode/notes/ui/NoteItemData.java
@@ -40,6 +40,7 @@ public class NoteItemData {
NoteColumns.TYPE,
NoteColumns.WIDGET_ID,
NoteColumns.WIDGET_TYPE,
+ NoteColumns.PASSWORD
};
private static final int ID_COLUMN = 0;
@@ -54,6 +55,7 @@ public class NoteItemData {
private static final int TYPE_COLUMN = 9;
private static final int WIDGET_ID_COLUMN = 10;
private static final int WIDGET_TYPE_COLUMN = 11;
+ private static final int PASSWORD = 12;
private long mId;
private long mAlertDate;
@@ -70,6 +72,10 @@ public class NoteItemData {
private String mName;
private String mPhoneNumber;
private int mLocked;
+<<<<<<< HEAD
+=======
+ private String mPassword = "";
+>>>>>>> xiaojinchi_branch
private boolean mIsLastItem;
private boolean mIsFirstItem;
@@ -92,6 +98,7 @@ public class NoteItemData {
mType = cursor.getInt(TYPE_COLUMN);
mWidgetId = cursor.getInt(WIDGET_ID_COLUMN);
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
+ mPassword = cursor.getString(PASSWORD);
mPhoneNumber = "";
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {
@@ -215,6 +222,11 @@ public class NoteItemData {
return (mAlertDate > 0);
}
+<<<<<<< HEAD
+=======
+ public String getPassword(){ return mPassword;}
+
+>>>>>>> xiaojinchi_branch
public void locked(){ mLocked = 1;}
public boolean isCallRecord() {
diff --git a/src/Notes-master3/app/src/main/java/net/micode/notes/ui/NotesListActivity.java b/src/Notes-master3/app/src/main/java/net/micode/notes/ui/NotesListActivity.java
index faa94e4..5b17e03 100644
--- a/src/Notes-master3/app/src/main/java/net/micode/notes/ui/NotesListActivity.java
+++ b/src/Notes-master3/app/src/main/java/net/micode/notes/ui/NotesListActivity.java
@@ -62,7 +62,7 @@ import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
-
+import androidx.appcompat.app.AppCompatActivity;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
diff --git a/src/Notes-master3/app/src/main/java/net/micode/notes/ui/ScreenListener.java b/src/Notes-master3/app/src/main/java/net/micode/notes/ui/ScreenListener.java
new file mode 100644
index 0000000..ebbbfe6
--- /dev/null
+++ b/src/Notes-master3/app/src/main/java/net/micode/notes/ui/ScreenListener.java
@@ -0,0 +1,130 @@
+package net.micode.notes.ui;
+
+
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.PowerManager;
+
+
+public class ScreenListener {
+ private Context mContext;
+ private ScreenBroadcastReceiver mScreenReceiver;
+ private ScreenStateListener mScreenStateListener;
+
+
+ public ScreenListener(Context context) {
+ mContext = context;
+ mScreenReceiver = new ScreenBroadcastReceiver();
+ }
+
+
+ /**
+ * Status screen broadcast receivers
+ */
+ private class ScreenBroadcastReceiver extends BroadcastReceiver {
+ private String action = null;
+
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ action = intent.getAction();
+ if (Intent.ACTION_SCREEN_ON.equals(action)) { // Open screen
+ mScreenStateListener.onScreenOn();
+ } else if (Intent.ACTION_SCREEN_OFF.equals(action)) { // Lock screen
+ mScreenStateListener.onScreenOff();
+ } else if (Intent.ACTION_USER_PRESENT.equals(action)) { // Unlock
+ mScreenStateListener.onUserPresent();
+ }
+ }
+ }
+
+
+ /**
+ * Start listening screen state
+ *
+ * @param listener
+ */
+ public void begin(ScreenStateListener listener) {
+ mScreenStateListener = listener;
+ registerListener();
+ getScreenState();
+ }
+
+
+ /**
+ * Get status screen
+ */
+ private void getScreenState() {
+ PowerManager manager = (PowerManager) mContext
+ .getSystemService(Context.POWER_SERVICE);
+ if (manager.isScreenOn()) {
+ if (mScreenStateListener != null) {
+ mScreenStateListener.onScreenOn();
+ }
+ } else {
+ if (mScreenStateListener != null) {
+ mScreenStateListener.onScreenOff();
+ }
+ }
+ }
+
+
+ /**
+ * Stop screen status monitor
+ */
+ public void unregisterListener() {
+ mContext.unregisterReceiver(mScreenReceiver);
+ }
+
+
+ /**
+ * Start screen broadcast receiver status
+ */
+ public void registerListener() {
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(Intent.ACTION_SCREEN_ON);
+ filter.addAction(Intent.ACTION_SCREEN_OFF);
+ filter.addAction(Intent.ACTION_USER_PRESENT);
+ mContext.registerReceiver(mScreenReceiver, filter);
+ }
+
+ /**
+ * Returned to the caller screen status information
+ */
+ public interface ScreenStateListener {
+ public void onScreenOn();
+
+
+ public void onScreenOff();
+
+
+ public void onUserPresent();
+ }
+/**
+ * Interface calls
+ ScreenListener l = new ScreenListener(this);
+ l.begin(new ScreenStateListener() {
+
+
+@Override
+public void onUserPresent() {
+Log.e("onUserPresent", "onUserPresent");
+}
+
+
+@Override
+public void onScreenOn() {
+Log.e("onScreenOn", "onScreenOn");
+}
+
+
+@Override
+public void onScreenOff() {
+Log.e("onScreenOff", "onScreenOff");
+}
+ **/
+
+}
\ No newline at end of file
diff --git a/src/Notes-master3/app/src/main/java/net/micode/notes/ui/SpeechApplication.java b/src/Notes-master3/app/src/main/java/net/micode/notes/ui/SpeechApplication.java
new file mode 100644
index 0000000..de97633
--- /dev/null
+++ b/src/Notes-master3/app/src/main/java/net/micode/notes/ui/SpeechApplication.java
@@ -0,0 +1,16 @@
+package net.micode.notes.ui;
+
+import android.app.Application;
+
+import com.iflytek.cloud.SpeechUtility;
+
+public class SpeechApplication extends Application {
+
+ @Override
+ public void onCreate() {
+
+ // 5ef048e1 为在开放平台注册的APPID 注意没有空格,直接替换即可
+ SpeechUtility.createUtility(SpeechApplication.this, "appid=5ef048e1");
+ super.onCreate();
+ }
+}
diff --git a/src/Notes-master3/app/src/main/res/layout/note_edit.xml b/src/Notes-master3/app/src/main/res/layout/note_edit.xml
index b69302d..024f190 100644
--- a/src/Notes-master3/app/src/main/res/layout/note_edit.xml
+++ b/src/Notes-master3/app/src/main/res/layout/note_edit.xml
@@ -54,12 +54,21 @@
android:layout_marginLeft="2dip"
android:layout_marginRight="8dip"
android:textAppearance="@style/TextAppearanceSecondaryItem" />
-
-
+
+
+<<<<<<< HEAD
+=======
+
+
+
+
+
+
+>>>>>>> xiaojinchi_branch
diff --git a/src/Notes-master3/app/src/main/res/menu/note_edit.xml b/src/Notes-master3/app/src/main/res/menu/note_edit.xml
index ce54c57..d4c54b1 100644
--- a/src/Notes-master3/app/src/main/res/menu/note_edit.xml
+++ b/src/Notes-master3/app/src/main/res/menu/note_edit.xml
@@ -60,7 +60,10 @@
android:title="add image" >
diff --git a/src/Notes-master3/core/.DS_Store b/src/Notes-master3/core/.DS_Store
new file mode 100644
index 0000000..5008ddf
Binary files /dev/null and b/src/Notes-master3/core/.DS_Store differ
diff --git a/src/Notes-master3/core/.gitignore b/src/Notes-master3/core/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/src/Notes-master3/core/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/src/Notes-master3/core/build.gradle b/src/Notes-master3/core/build.gradle
new file mode 100644
index 0000000..6c9d9ed
--- /dev/null
+++ b/src/Notes-master3/core/build.gradle
@@ -0,0 +1,29 @@
+apply plugin: 'com.android.library'
+
+
+android {
+ compileSdkVersion 28
+
+ defaultConfig {
+ minSdkVersion 16
+ targetSdkVersion 28
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ }
+ }
+ packagingOptions{
+ doNotStrip "*/*/libvad.dnn.so"
+ doNotStrip "*/*/libbd_easr_s1_merge_normal_20151216.dat.so"
+ }
+}
+
+
+
+dependencies {
+ api fileTree(include: ['*.jar'], dir: 'libs')
+ implementation 'androidx.appcompat:appcompat:1.0.2'
+}
diff --git a/src/Notes-master3/core/core.iml b/src/Notes-master3/core/core.iml
new file mode 100644
index 0000000..290b3b6
--- /dev/null
+++ b/src/Notes-master3/core/core.iml
@@ -0,0 +1,125 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ generateDebugSources
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master3/core/libs/bdasr_V3_20210628_cfe8c44.jar b/src/Notes-master3/core/libs/bdasr_V3_20210628_cfe8c44.jar
new file mode 100644
index 0000000..927c281
Binary files /dev/null and b/src/Notes-master3/core/libs/bdasr_V3_20210628_cfe8c44.jar differ
diff --git a/src/Notes-master3/core/proguard-rules.pro b/src/Notes-master3/core/proguard-rules.pro
new file mode 100644
index 0000000..f1b4245
--- /dev/null
+++ b/src/Notes-master3/core/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
diff --git a/src/Notes-master3/core/src/main/AndroidManifest.xml b/src/Notes-master3/core/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..d120add
--- /dev/null
+++ b/src/Notes-master3/core/src/main/AndroidManifest.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Notes-master3/core/src/main/assets/README.txt b/src/Notes-master3/core/src/main/assets/README.txt
new file mode 100644
index 0000000..357557e
--- /dev/null
+++ b/src/Notes-master3/core/src/main/assets/README.txt
@@ -0,0 +1,3 @@
+百度语音识别SDK在demo程序中assets目录的文件解释说明:
+WakeUp.bin 唤醒功能的唤醒词配置文件, 需要在百度语音开发平台中定义和导出 http://speech.baidu.com/wake
+baidu_speech_grammar.bsg 自定义语义以及离线命令词识别共用的语法文件, 需要在百度语音开发平台中定义和导出 http://speech.baidu.com/asr
\ No newline at end of file
diff --git a/src/Notes-master3/core/src/main/assets/WakeUp.bin b/src/Notes-master3/core/src/main/assets/WakeUp.bin
new file mode 100644
index 0000000..88fca58
--- /dev/null
+++ b/src/Notes-master3/core/src/main/assets/WakeUp.bin
@@ -0,0 +1 @@
+fAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZBfAEYGGtOpEYB_ZB
\ No newline at end of file
diff --git a/src/Notes-master3/core/src/main/assets/baidu_speech_grammar.bsg b/src/Notes-master3/core/src/main/assets/baidu_speech_grammar.bsg
new file mode 100644
index 0000000..7eda192
--- /dev/null
+++ b/src/Notes-master3/core/src/main/assets/baidu_speech_grammar.bsg
@@ -0,0 +1 @@
+%7B%0A%20%20%20%20%22version%22%3A%20%220.1%22%2C%0A%20%20%20%20%22slots%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22name%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%E5%BC%A0%E4%B8%89%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%E6%9D%8E%E5%9B%9B%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%E7%8E%8B%E4%BA%94%22%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%22appname%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%E5%BE%AE%E4%BF%A1%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%E7%9F%AD%E4%BF%A1%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22%E8%AE%A1%E7%AE%97%E5%99%A8%22%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%22msgbody%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22.%2B%22%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%22rules%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22telephone.call%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22origin%22%3A%20%22%E6%89%93%E7%94%B5%E8%AF%9D%E7%BB%99%3Cname%3E%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pattern%22%3A%20%22%5E%E6%89%93%E7%94%B5%E8%AF%9D%E7%BB%99(%E5%BC%A0%E4%B8%89%7C%E6%9D%8E%E5%9B%9B%7C%E7%8E%8B%E4%BA%94)%24%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22groups%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22origin%22%3A%20%22%E6%89%93%E7%BB%99%3Cname%3E%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pattern%22%3A%20%22%5E%E6%89%93%E7%BB%99(%E5%BC%A0%E4%B8%89%7C%E6%9D%8E%E5%9B%9B%7C%E7%8E%8B%E4%BA%94)%24%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22groups%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22origin%22%3A%20%22%E5%91%BC%E5%8F%AB%3Cname%3E%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pattern%22%3A%20%22%5E%E5%91%BC%E5%8F%AB(%E5%BC%A0%E4%B8%89%7C%E6%9D%8E%E5%9B%9B%7C%E7%8E%8B%E4%BA%94)%24%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22groups%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22origin%22%3A%20%22%E7%BB%99%3Cname%3E%E6%89%93%E7%94%B5%E8%AF%9D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pattern%22%3A%20%22%5E%E7%BB%99(%E5%BC%A0%E4%B8%89%7C%E6%9D%8E%E5%9B%9B%7C%E7%8E%8B%E4%BA%94)%E6%89%93%E7%94%B5%E8%AF%9D%24%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22groups%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%22contacts.view%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22origin%22%3A%20%22%E6%9F%A5%E7%9C%8B%3Cname%3E%E7%9A%84%E7%94%B5%E8%AF%9D%E5%8F%B7%E7%A0%81%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pattern%22%3A%20%22%5E%E6%9F%A5%E7%9C%8B(%E5%BC%A0%E4%B8%89%7C%E6%9D%8E%E5%9B%9B%7C%E7%8E%8B%E4%BA%94)%E7%9A%84%E7%94%B5%E8%AF%9D%E5%8F%B7%E7%A0%81%24%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22groups%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22origin%22%3A%20%22%E6%9F%A5%E7%9C%8B%3Cname%3E%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pattern%22%3A%20%22%5E%E6%9F%A5%E7%9C%8B(%E5%BC%A0%E4%B8%89%7C%E6%9D%8E%E5%9B%9B%7C%E7%8E%8B%E4%BA%94)%24%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22groups%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%22contacts.create%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22origin%22%3A%20%22%E6%96%B0%E5%BB%BA%E8%81%94%E7%B3%BB%E4%BA%BA%3Cname%3E%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pattern%22%3A%20%22%5E%E6%96%B0%E5%BB%BA%E8%81%94%E7%B3%BB%E4%BA%BA(%E5%BC%A0%E4%B8%89%7C%E6%9D%8E%E5%9B%9B%7C%E7%8E%8B%E4%BA%94)%24%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22groups%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%22contacts.remove%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22origin%22%3A%20%22%E5%88%A0%E9%99%A4%3Cname%3E%E7%9A%84%E8%81%94%E7%B3%BB%E6%96%B9%E5%BC%8F%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pattern%22%3A%20%22%5E%E5%88%A0%E9%99%A4(%E5%BC%A0%E4%B8%89%7C%E6%9D%8E%E5%9B%9B%7C%E7%8E%8B%E4%BA%94)%E7%9A%84%E8%81%94%E7%B3%BB%E6%96%B9%E5%BC%8F%24%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22groups%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%22message.view%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22origin%22%3A%20%22%E6%9F%A5%E7%9C%8B%E6%9C%AA%E8%AF%BB%E7%9F%AD%E4%BF%A1%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pattern%22%3A%20%22%5E%E6%9F%A5%E7%9C%8B%E6%9C%AA%E8%AF%BB%E7%9F%AD%E4%BF%A1%24%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22groups%22%3A%20%5B%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%22message.send%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22origin%22%3A%20%22%E5%8F%91%E7%9F%AD%E4%BF%A1%E7%BB%99%3Cname%3E%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pattern%22%3A%20%22%5E%E5%8F%91%E7%9F%AD%E4%BF%A1%E7%BB%99(%E5%BC%A0%E4%B8%89%7C%E6%9D%8E%E5%9B%9B%7C%E7%8E%8B%E4%BA%94)%24%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22groups%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22origin%22%3A%20%22%E5%8F%91%E7%9F%AD%E4%BF%A1%E7%BB%99%3Cname%3E%E5%86%85%E5%AE%B9%E6%98%AF%3Cmsgbody%3E%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pattern%22%3A%20%22%5E%E5%8F%91%E7%9F%AD%E4%BF%A1%E7%BB%99(%E5%BC%A0%E4%B8%89%7C%E6%9D%8E%E5%9B%9B%7C%E7%8E%8B%E4%BA%94)%E5%86%85%E5%AE%B9%E6%98%AF(.%2B)%24%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22groups%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22msgbody%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%22app.open%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22origin%22%3A%20%22%E6%89%93%E5%BC%80%3Cappname%3E%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pattern%22%3A%20%22%5E%E6%89%93%E5%BC%80(%E5%BE%AE%E4%BF%A1%7C%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE%7C%E7%9F%AD%E4%BF%A1%7C%E8%AE%A1%E7%AE%97%E5%99%A8)%24%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22groups%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22appname%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22origin%22%3A%20%22%E5%90%AF%E5%8A%A8%3Cappname%3E%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pattern%22%3A%20%22%5E%E5%90%AF%E5%8A%A8(%E5%BE%AE%E4%BF%A1%7C%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE%7C%E7%9F%AD%E4%BF%A1%7C%E8%AE%A1%E7%AE%97%E5%99%A8)%24%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22groups%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22appname%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%22app.search%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22origin%22%3A%20%22%E6%90%9C%E7%B4%A2%3Cappname%3E%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pattern%22%3A%20%22%5E%E6%90%9C%E7%B4%A2(%E5%BE%AE%E4%BF%A1%7C%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE%7C%E7%9F%AD%E4%BF%A1%7C%E8%AE%A1%E7%AE%97%E5%99%A8)%24%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22groups%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22appname%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%22app.download%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22origin%22%3A%20%22%E4%B8%8B%E8%BD%BD%3Cappname%3E%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pattern%22%3A%20%22%5E%E4%B8%8B%E8%BD%BD(%E5%BE%AE%E4%BF%A1%7C%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE%7C%E7%9F%AD%E4%BF%A1%7C%E8%AE%A1%E7%AE%97%E5%99%A8)%24%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22groups%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22appname%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%22grammar%22%3A%20%22%3Cname%3E%20%3D%20%E5%BC%A0%E4%B8%89%7C%20%5Cn%E6%9D%8E%E5%9B%9B%7C%20%5Cn%E7%8E%8B%E4%BA%94%3B%5Cn%3Cappname%3E%20%3D%20%E5%BE%AE%E4%BF%A1%7C%20%5Cn%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE%7C%20%5Cn%E7%9F%AD%E4%BF%A1%7C%20%5Cn%E8%AE%A1%E7%AE%97%E5%99%A8%3B%5Cn%3Cmsgbody%3E%20%3D%20%E8%AF%8D%E6%9D%A1%E9%BB%98%E8%AE%A4%E5%80%BC%3B%5Cn%3Cauto_create_node%3E%20%3D%20%E6%9F%A5%E7%9C%8B%E6%9C%AA%E8%AF%BB%E7%9F%AD%E4%BF%A1%3B%5Cn%3C_wakeup%3E%20%3D%20%E5%94%A4%E9%86%92%E8%AF%8D%E5%8D%A0%E4%BD%8D%E7%AC%A6%3B%5Cn%5Cn%5Cn_SCENE_ID_%200%5Cn%5Cn(%20%3Cauto_create_node%3E%20)%5Cn%5Cn(%20%3C_wakeup%3E%3Cauto_create_node%3E%20)%5Cn%5Cn(%20%E6%89%93%E7%94%B5%E8%AF%9D%E7%BB%99%3Cname%3E%20)%5Cn(%20%3C_wakeup%3E%E6%89%93%E7%94%B5%E8%AF%9D%E7%BB%99%3Cname%3E%20)%5Cn(%20%E6%89%93%E7%BB%99%3Cname%3E%20)%5Cn(%20%3C_wakeup%3E%E6%89%93%E7%BB%99%3Cname%3E%20)%5Cn(%20%E5%91%BC%E5%8F%AB%3Cname%3E%20)%5Cn(%20%3C_wakeup%3E%E5%91%BC%E5%8F%AB%3Cname%3E%20)%5Cn(%20%E7%BB%99%3Cname%3E%E6%89%93%E7%94%B5%E8%AF%9D%20)%5Cn(%20%3C_wakeup%3E%E7%BB%99%3Cname%3E%E6%89%93%E7%94%B5%E8%AF%9D%20)%5Cn(%20%E6%9F%A5%E7%9C%8B%3Cname%3E%E7%9A%84%E7%94%B5%E8%AF%9D%E5%8F%B7%E7%A0%81%20)%5Cn(%20%3C_wakeup%3E%E6%9F%A5%E7%9C%8B%3Cname%3E%E7%9A%84%E7%94%B5%E8%AF%9D%E5%8F%B7%E7%A0%81%20)%5Cn(%20%E6%9F%A5%E7%9C%8B%3Cname%3E%20)%5Cn(%20%3C_wakeup%3E%E6%9F%A5%E7%9C%8B%3Cname%3E%20)%5Cn(%20%E6%96%B0%E5%BB%BA%E8%81%94%E7%B3%BB%E4%BA%BA%3Cname%3E%20)%5Cn(%20%3C_wakeup%3E%E6%96%B0%E5%BB%BA%E8%81%94%E7%B3%BB%E4%BA%BA%3Cname%3E%20)%5Cn(%20%E5%88%A0%E9%99%A4%3Cname%3E%E7%9A%84%E8%81%94%E7%B3%BB%E6%96%B9%E5%BC%8F%20)%5Cn(%20%3C_wakeup%3E%E5%88%A0%E9%99%A4%3Cname%3E%E7%9A%84%E8%81%94%E7%B3%BB%E6%96%B9%E5%BC%8F%20)%5Cn(%20%E5%8F%91%E7%9F%AD%E4%BF%A1%E7%BB%99%3Cname%3E%20)%5Cn(%20%3C_wakeup%3E%E5%8F%91%E7%9F%AD%E4%BF%A1%E7%BB%99%3Cname%3E%20)%5Cn(%20%E5%8F%91%E7%9F%AD%E4%BF%A1%E7%BB%99%3Cname%3E%E5%86%85%E5%AE%B9%E6%98%AF%3Cmsgbody%3E%20)%5Cn(%20%3C_wakeup%3E%E5%8F%91%E7%9F%AD%E4%BF%A1%E7%BB%99%3Cname%3E%E5%86%85%E5%AE%B9%E6%98%AF%3Cmsgbody%3E%20)%5Cn(%20%E6%89%93%E5%BC%80%3Cappname%3E%20)%5Cn(%20%3C_wakeup%3E%E6%89%93%E5%BC%80%3Cappname%3E%20)%5Cn(%20%E5%90%AF%E5%8A%A8%3Cappname%3E%20)%5Cn(%20%3C_wakeup%3E%E5%90%AF%E5%8A%A8%3Cappname%3E%20)%5Cn(%20%E6%90%9C%E7%B4%A2%3Cappname%3E%20)%5Cn(%20%3C_wakeup%3E%E6%90%9C%E7%B4%A2%3Cappname%3E%20)%5Cn(%20%E4%B8%8B%E8%BD%BD%3Cappname%3E%20)%5Cn(%20%3C_wakeup%3E%E4%B8%8B%E8%BD%BD%3Cappname%3E%20)%5Cn%22%2C%0A%20%20%20%20%22origin_slots%22%3A%20%22name%20%3D%20%E5%BC%A0%E4%B8%89%2C%20%E6%9D%8E%E5%9B%9B%2C%20%E7%8E%8B%E4%BA%94%5Cnappname%20%3D%20%E5%BE%AE%E4%BF%A1%2C%20%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE%2C%20%E7%9F%AD%E4%BF%A1%2C%20%E8%AE%A1%E7%AE%97%E5%99%A8%5Cnmsgbody%20%3D%20*%22%2C%0A%20%20%20%20%22origin_rules%22%3A%20%22telephone.call%20%20%20%20%20%3D%20%E6%89%93%E7%94%B5%E8%AF%9D%E7%BB%99%3Cname%3E%2C%20%E6%89%93%E7%BB%99%3Cname%3E%2C%20%E5%91%BC%E5%8F%AB%3Cname%3E%2C%E7%BB%99%3Cname%3E%E6%89%93%E7%94%B5%E8%AF%9D%5Cncontacts.view%20%20%20%20%20%3D%20%E6%9F%A5%E7%9C%8B%3Cname%3E%E7%9A%84%E7%94%B5%E8%AF%9D%E5%8F%B7%E7%A0%81%2C%20%E6%9F%A5%E7%9C%8B%3Cname%3E%5Cncontacts.create%20%20%3D%20%E6%96%B0%E5%BB%BA%E8%81%94%E7%B3%BB%E4%BA%BA%3Cname%3E%5Cncontacts.remove%3D%20%E5%88%A0%E9%99%A4%3Cname%3E%E7%9A%84%E8%81%94%E7%B3%BB%E6%96%B9%E5%BC%8F%5Cnmessage.view%20%20%20%20%20%3D%20%E6%9F%A5%E7%9C%8B%E6%9C%AA%E8%AF%BB%E7%9F%AD%E4%BF%A1%5Cnmessage.send%20%20%20%20%3D%20%E5%8F%91%E7%9F%AD%E4%BF%A1%E7%BB%99%3Cname%3E%2C%20%E5%8F%91%E7%9F%AD%E4%BF%A1%E7%BB%99%3Cname%3E%E5%86%85%E5%AE%B9%E6%98%AF%3Cmsgbody%3E%5Cnapp.open%20%20%20%20%20%20%20%20%20%20%20%20%3D%20%E6%89%93%E5%BC%80%3Cappname%3E%2C%20%E5%90%AF%E5%8A%A8%3Cappname%3E%5Cnapp.search%20%20%20%20%20%20%20%20%20%3D%20%E6%90%9C%E7%B4%A2%3Cappname%3E%5Cnapp.download%20%20%20%20%3D%20%E4%B8%8B%E8%BD%BD%3Cappname%3E%22%0A%7D
\ No newline at end of file
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/inputstream/FileAudioInputStream.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/inputstream/FileAudioInputStream.java
new file mode 100644
index 0000000..74b497e
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/inputstream/FileAudioInputStream.java
@@ -0,0 +1,98 @@
+package com.baidu.aip.asrwakeup3.core.inputstream;
+
+import android.util.Log;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigInteger;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * Created by fujiayi on 2017/11/27.
+ *
+ * 解决大文件的输入问题。
+ * 文件大时不能通过Infile参数一下子输入。
+ */
+
+public class FileAudioInputStream extends InputStream {
+
+ private InputStream in;
+
+ private long nextSleepTime = -1;
+
+ private long totalSleepMs = 0;
+
+ private static final String TAG = "FileAudioInputStream";
+
+ public FileAudioInputStream(String file) throws FileNotFoundException {
+ in = new FileInputStream(file);
+ }
+
+ public FileAudioInputStream(InputStream in) {
+ this.in = in;
+ }
+
+ @Override
+ public int read() throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
+ int bytePerMs = 16000 * 2 / 1000;
+ int count = bytePerMs * 20; // 20ms 音频数据
+ if (byteCount < count) {
+ count = byteCount;
+ }
+ if (nextSleepTime > 0) {
+ try {
+ long sleepMs = nextSleepTime - System.currentTimeMillis();
+ if (sleepMs > 0) {
+ Log.i(TAG, "will sleep " + sleepMs);
+ Thread.sleep(sleepMs); // 每20ms的音频 ,比如等待20ms传输下一批
+ totalSleepMs += sleepMs;
+ }
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ int r = in.read(buffer, byteOffset, count);
+
+ /*
+ if (r >= 0) {
+ Log.i("FileAudioInputStream", "Debug:" + System.currentTimeMillis() + ": " + md5(buffer, byteOffset, r));
+ } else {
+ Log.i("FileAudioInputStream", "Debug:" + System.currentTimeMillis() + ": return " + r);
+ }
+ */
+ nextSleepTime = System.currentTimeMillis() + r / bytePerMs;
+
+ // 如果是长语音,在r=-1的情况下,需要手动调用stop
+ return r;
+ }
+
+ @Override
+ public void close() throws IOException {
+ super.close();
+ Log.i(TAG, "time sleeped " + totalSleepMs);
+ if (null != in) {
+ in.close();
+ }
+ }
+
+ private String md5(byte[] buffer, int byteOffset, int byteCount) {
+ try {
+ MessageDigest digest = MessageDigest.getInstance("MD5");
+ digest.reset();
+ digest.update(buffer, byteOffset, byteCount);
+ BigInteger bigInt = new BigInteger(1, digest.digest());
+ return bigInt.toString(16);
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/inputstream/InFileStream.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/inputstream/InFileStream.java
new file mode 100644
index 0000000..eebc3cb
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/inputstream/InFileStream.java
@@ -0,0 +1,105 @@
+package com.baidu.aip.asrwakeup3.core.inputstream;
+
+import android.app.Activity;
+import android.content.Context;
+
+import com.baidu.aip.asrwakeup3.core.util.MyLogger;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Created by fujiayi on 2017/6/20.
+ */
+
+public class InFileStream {
+
+ private static Context context;
+
+ private static final String TAG = "InFileStream";
+
+ private static volatile String filename;
+
+ private static volatile InputStream is;
+
+ // 以下3个setContext
+
+ /**
+ * 必须要先调用这个方法
+ * 如之后调用create16kStream,使用默认的app/src/main/assets/outfile.pcm作为输入
+ * 如之后调用createMyPipedInputStream, 见 InPipedStream
+ *
+ * @param context
+ */
+ public static void setContext(Context context) {
+ InFileStream.context = context;
+ }
+
+ /**
+ * 使用pcm文件作为输入
+ *
+ * @param context
+ * @param filename
+ */
+ public static void setContext(Context context, String filename) {
+ InFileStream.context = context;
+ InFileStream.filename = filename;
+ }
+
+ public static void setContext(Context context, InputStream is) {
+ InFileStream.context = context;
+ InFileStream.is = is;
+ }
+
+ public static Context getContext() {
+ return context;
+ }
+
+ public static void reset() {
+ filename = null;
+ is = null;
+ }
+
+
+ public static InputStream createMyPipedInputStream() {
+ return InPipedStream.createAndStart(context);
+ }
+
+ /**
+ * 默认使用必须要先调用setContext
+ * 默认从createFileStream中读取InputStream
+ *
+ * @return
+ */
+ public static InputStream create16kStream() {
+ if (is == null && filename == null) {
+ // 没有任何设置的话,从createFileStream中读取
+ return new FileAudioInputStream(createFileStream());
+ }
+
+ if (is != null) { // 默认为null,setInputStream调用后走这个逻辑
+ return new FileAudioInputStream(is);
+ } else if (filename != null) { // 默认为null, setFileName调用后走这个逻辑
+ try {
+ return new FileAudioInputStream(filename);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return null;
+ }
+
+ private static InputStream createFileStream() {
+ try {
+ // 这里抛异常表示没有调用 setContext方法
+ InputStream is = context.getAssets().open("outfile.pcm");
+ MyLogger.info(TAG, "create input stream ok " + is.available());
+ return is;
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/inputstream/InPipedStream.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/inputstream/InPipedStream.java
new file mode 100644
index 0000000..9b89b36
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/inputstream/InPipedStream.java
@@ -0,0 +1,82 @@
+package com.baidu.aip.asrwakeup3.core.inputstream;
+
+import android.content.Context;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+
+/**
+ * 本示例从app/src/main/assets/outfile.pcm作为byte[]的输入
+ * 生成PipedInputStream作为SDK里IN_FILE的参数
+ */
+public class InPipedStream {
+
+ private PipedInputStream pipedInputStream;
+ private PipedOutputStream pipedOutputStream;
+ private Context context;
+
+ private InPipedStream(Context context) {
+ pipedInputStream = new PipedInputStream();
+ pipedOutputStream = new PipedOutputStream();
+ this.context = context;
+ }
+
+ private void start() throws IOException {
+ /** 准备绑定 **/
+ pipedInputStream.connect(pipedOutputStream);
+
+ /** 准备文件 **/
+
+ /** 新线程中放入 20ms 音频数据,注意从新线程放入**/
+ Runnable run = new Runnable() {
+ @Override
+ public void run() {
+
+ try {
+ final InputStream is = context.getAssets().open("outfile.pcm");
+ /** 读取20ms的音频二进制数据 放入buffer 中**/
+ int bytePerMs = 16000 * 2 / 1000;
+ int count = bytePerMs * 20; // 20ms 音频数据
+ int r = 0;
+ byte[] buffer = new byte[count];
+ do {
+ r = is.read(buffer);
+ int sleepTime = 0;
+ if (r > 0) {
+ pipedOutputStream.write(buffer, 0, count);
+ sleepTime = r / bytePerMs;
+ } else if (r == 0) {
+ sleepTime = 100; // 这里数值按照自己情况而定
+ }
+ if (sleepTime > 0) {
+ try {
+ Thread.sleep(sleepTime);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ } while (r >= 0);
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ }
+ };
+ (new Thread(run)).start();
+ }
+
+ public static PipedInputStream createAndStart(Context context) {
+ InPipedStream obj = new InPipedStream(context);
+ try {
+ obj.start();
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ return obj.pipedInputStream;
+ }
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/inputstream/MyMicrophoneInputStream.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/inputstream/MyMicrophoneInputStream.java
new file mode 100644
index 0000000..8be10c5
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/inputstream/MyMicrophoneInputStream.java
@@ -0,0 +1,100 @@
+package com.baidu.aip.asrwakeup3.core.inputstream;
+
+import android.content.Context;
+import android.media.AudioFormat;
+import android.media.AudioRecord;
+import android.media.MediaRecorder;
+import android.util.Log;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Created by fujiayi on 2017/11/27.
+ */
+
+public class MyMicrophoneInputStream extends InputStream {
+ private static AudioRecord audioRecord;
+
+ private static MyMicrophoneInputStream is;
+
+ private boolean isStarted = false;
+
+ private static final String TAG = "MyMicrophoneInputStream";
+
+ public MyMicrophoneInputStream() {
+ if (audioRecord == null) {
+ int bufferSize = AudioRecord.getMinBufferSize(16000,
+ AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT) * 16;
+ audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
+ 16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
+
+
+ }
+
+
+ }
+
+ public static MyMicrophoneInputStream getInstance() {
+ if (is == null) {
+ synchronized (MyMicrophoneInputStream.class) {
+ if (is == null) {
+ is = new MyMicrophoneInputStream();
+ }
+ }
+ }
+ return is;
+ }
+
+ public void start() {
+ Log.i(TAG, " MyMicrophoneInputStream start recoding!");
+ try {
+ if (audioRecord == null
+ || audioRecord.getState() != AudioRecord.STATE_INITIALIZED) {
+ throw new IllegalStateException(
+ "startRecording() called on an uninitialized AudioRecord." + (audioRecord == null));
+ }
+
+ Context context = InFileStream.getContext();
+
+ audioRecord.startRecording();
+
+ } catch (Exception e) {
+ Log.e(TAG, e.getClass().getSimpleName(), e);
+ }
+ Log.i(TAG, " MyMicrophoneInputStream start recoding finished");
+ }
+
+ @Override
+ public int read() throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+
+ if (!isStarted) {
+ start(); // 建议在CALLBACK_EVENT_ASR_READY事件中调用。
+ isStarted = true;
+ }
+ try {
+ int count = audioRecord.read(b, off, len);
+ return count;
+ } catch (Exception e) {
+ Log.e(TAG, e.getClass().getSimpleName(), e);
+ throw e;
+ }
+
+ }
+
+ // 建议在建议在CALLBACK_EVENT_ASR_EXIT事件中调用
+ @Override
+ public void close() throws IOException {
+ Log.i(TAG, " MyMicrophoneInputStream close");
+ if (audioRecord != null) {
+ audioRecord.stop();
+ // audioRecord.release(); 程序结束别忘记自行释放
+ isStarted = false;
+ }
+ }
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/mini/ActivityMiniRecog.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/mini/ActivityMiniRecog.java
new file mode 100644
index 0000000..532b383
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/mini/ActivityMiniRecog.java
@@ -0,0 +1,283 @@
+package com.baidu.aip.asrwakeup3.core.mini;
+
+import android.Manifest;
+import android.content.pm.PackageManager;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.app.ActivityCompat;
+import androidx.core.content.ContextCompat;
+
+import com.baidu.aip.asrwakeup3.core.R;
+import com.baidu.aip.asrwakeup3.core.util.AuthUtil;
+import com.baidu.speech.EventListener;
+import com.baidu.speech.EventManager;
+import com.baidu.speech.EventManagerFactory;
+import com.baidu.speech.asr.SpeechConstant;
+
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * 集成文档: http://ai.baidu.com/docs#/ASR-Android-SDK/top 集成指南一节
+ * demo目录下doc_integration_DOCUMENT
+ * ASR-INTEGRATION-helloworld ASR集成指南-集成到helloworld中 对应 ActivityMiniRecog
+ * ASR-INTEGRATION-TTS-DEMO ASR集成指南-集成到合成DEMO中 对应 ActivityRecog
+ */
+
+public class ActivityMiniRecog extends AppCompatActivity implements EventListener {
+ protected TextView txtLog;
+ protected TextView txtResult;
+ protected Button btn;
+ protected Button stopBtn;
+ private static String DESC_TEXT = "精简版识别,带有SDK唤醒运行的最少代码,仅仅展示如何调用,\n" +
+ "也可以用来反馈测试SDK输入参数及输出回调。\n" +
+ "本示例需要自行根据文档填写参数,可以使用之前识别示例中的日志中的参数。\n" +
+ "需要完整版请参见之前的识别示例。\n" +
+ "需要测试离线命令词识别功能可以将本类中的enableOffline改成true,首次测试离线命令词请联网使用。之后请说出“打电话给李四”";
+
+ private EventManager asr;
+
+ private boolean logTime = true;
+
+ protected boolean enableOffline = false; // 测试离线命令词,需要改成true
+
+ /**
+ * 基于SDK集成2.2 发送开始事件
+ * 点击开始按钮
+ * 测试参数填在这里
+ */
+ private void start() {
+ txtLog.setText("");
+ Map params = AuthUtil.getParam();
+ String event = null;
+ event = SpeechConstant.ASR_START; // 替换成测试的event
+
+ if (enableOffline) {
+ params.put(SpeechConstant.DECODER, 2);
+ }
+ // 基于SDK集成2.1 设置识别参数
+ params.put(SpeechConstant.ACCEPT_AUDIO_VOLUME, false);
+ // params.put(SpeechConstant.NLU, "enable");
+ // params.put(SpeechConstant.BDS_ASR_ENABLE_LONG_SPEECH, true);//长语音 优先级高于VAD_ENDPOINT_TIMEOUT
+ // params.put(SpeechConstant.VAD_ENDPOINT_TIMEOUT, 0); // 长语音
+
+ // params.put(SpeechConstant.IN_FILE, "res:///com/baidu/android/voicedemo/16k_test.pcm");
+ // params.put(SpeechConstant.VAD, SpeechConstant.VAD_DNN);
+ // params.put(SpeechConstant.PID, 1537); // 中文输入法模型,有逗号
+
+ /* 语音自训练平台特有参数 */
+ // params.put(SpeechConstant.PID, 8002);
+ // 语音自训练平台特殊pid,8002:模型类似开放平台 1537 具体是8001还是8002,看自训练平台页面上的显示
+ // params.put(SpeechConstant.LMID,1068);
+ // 语音自训练平台已上线的模型ID,https://ai.baidu.com/smartasr/model
+ // 注意模型ID必须在你的appId所在的百度账号下
+ /* 语音自训练平台特有参数 */
+
+ /* 测试InputStream*/
+ // InFileStream.setContext(this);
+ // params.put(SpeechConstant.IN_FILE,
+ // "#com.baidu.aip.asrwakeup3.core.inputstream.InFileStream.createMyPipedInputStream()");
+
+ // 请先使用如‘在线识别’界面测试和生成识别参数。 params同ActivityRecog类中myRecognizer.start(params);
+ // 复制此段可以自动检测错误
+ (new AutoCheck(getApplicationContext(), new Handler() {
+ public void handleMessage(Message msg) {
+ if (msg.what == 100) {
+ AutoCheck autoCheck = (AutoCheck) msg.obj;
+ synchronized (autoCheck) {
+ String message = autoCheck.obtainErrorMessage(); // autoCheck.obtainAllMessage();
+ txtLog.append(message + "\n");
+ ; // 可以用下面一行替代,在logcat中查看代码
+ // Log.w("AutoCheckMessage", message);
+ }
+ }
+ }
+ }, enableOffline)).checkAsr(params);
+ String json = null; // 可以替换成自己的json
+ json = new JSONObject(params).toString(); // 这里可以替换成你需要测试的json
+ asr.send(event, json, null, 0, 0);
+ printLog("输入参数:" + json);
+ }
+
+ /**
+ * 点击停止按钮
+ * 基于SDK集成4.1 发送停止事件
+ */
+ private void stop() {
+ printLog("停止识别:ASR_STOP");
+ asr.send(SpeechConstant.ASR_STOP, null, null, 0, 0); //
+ }
+
+
+ /**
+ * enableOffline设为true时,在onCreate中调用
+ * 基于SDK离线命令词1.4 加载离线资源(离线时使用)
+ */
+ private void loadOfflineEngine() {
+ Map params = new LinkedHashMap();
+ params.put(SpeechConstant.DECODER, 2);
+ params.put(SpeechConstant.ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH, "assets://baidu_speech_grammar.bsg");
+ asr.send(SpeechConstant.ASR_KWS_LOAD_ENGINE, new JSONObject(params).toString(), null, 0, 0);
+ }
+
+ /**
+ * enableOffline为true时,在onDestory中调用,与loadOfflineEngine对应
+ * 基于SDK集成5.1 卸载离线资源步骤(离线时使用)
+ */
+ private void unloadOfflineEngine() {
+ asr.send(SpeechConstant.ASR_KWS_UNLOAD_ENGINE, null, null, 0, 0); //
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.common_mini);
+ initView();
+ initPermission();
+ // 基于sdk集成1.1 初始化EventManager对象
+ asr = EventManagerFactory.create(this, "asr");
+ // 基于sdk集成1.3 注册自己的输出事件类
+ asr.registerListener(this); // EventListener 中 onEvent方法
+ btn.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ start();
+ }
+ });
+ stopBtn.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ stop();
+ }
+ });
+ if (enableOffline) {
+ loadOfflineEngine(); // 测试离线命令词请开启, 测试 ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH 参数时开启
+ }
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ asr.send(SpeechConstant.ASR_CANCEL, "{}", null, 0, 0);
+ Log.i("ActivityMiniRecog", "On pause");
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ // 基于SDK集成4.2 发送取消事件
+ asr.send(SpeechConstant.ASR_CANCEL, "{}", null, 0, 0);
+ if (enableOffline) {
+ unloadOfflineEngine(); // 测试离线命令词请开启, 测试 ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH 参数时开启
+ }
+
+ // 基于SDK集成5.2 退出事件管理器
+ // 必须与registerListener成对出现,否则可能造成内存泄露
+ asr.unregisterListener(this);
+ }
+
+ // 基于sdk集成1.2 自定义输出事件类 EventListener 回调方法
+ // 基于SDK集成3.1 开始回调事件
+ @Override
+ public void onEvent(String name, String params, byte[] data, int offset, int length) {
+ String logTxt = "name: " + name;
+
+ if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL)) {
+ // 识别相关的结果都在这里
+ if (params == null || params.isEmpty()) {
+ return;
+ }
+ if (params.contains("\"nlu_result\"")) {
+ // 一句话的语义解析结果
+ if (length > 0 && data.length > 0) {
+ logTxt += ", 语义解析结果:" + new String(data, offset, length);
+ }
+ } else if (params.contains("\"partial_result\"")) {
+ // 一句话的临时识别结果
+ logTxt += ", 临时识别结果:" + params;
+ } else if (params.contains("\"final_result\"")) {
+ // 一句话的最终识别结果
+ logTxt += ", 最终识别结果:" + params;
+ } else {
+ // 一般这里不会运行
+ logTxt += " ;params :" + params;
+ if (data != null) {
+ logTxt += " ;data length=" + data.length;
+ }
+ }
+ } else {
+ // 识别开始,结束,音量,音频数据回调
+ if (params != null && !params.isEmpty()){
+ logTxt += " ;params :" + params;
+ }
+ if (data != null) {
+ logTxt += " ;data length=" + data.length;
+ }
+ }
+
+
+ printLog(logTxt);
+ }
+
+ private void printLog(String text) {
+ if (logTime) {
+ text += " ;time=" + System.currentTimeMillis();
+ }
+ text += "\n";
+ Log.i(getClass().getName(), text);
+ txtLog.append(text + "\n");
+ }
+
+
+ private void initView() {
+ txtResult = (TextView) findViewById(R.id.txtResult);
+ txtLog = (TextView) findViewById(R.id.txtLog);
+ btn = (Button) findViewById(R.id.btn);
+ stopBtn = (Button) findViewById(R.id.btn_stop);
+ txtLog.setText(DESC_TEXT + "\n");
+ }
+
+ /**
+ * android 6.0 以上需要动态申请权限
+ */
+ private void initPermission() {
+ String permissions[] = {Manifest.permission.RECORD_AUDIO,
+ Manifest.permission.ACCESS_NETWORK_STATE,
+ Manifest.permission.INTERNET,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE
+ };
+
+ ArrayList toApplyList = new ArrayList();
+
+ for (String perm : permissions) {
+ if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(this, perm)) {
+ toApplyList.add(perm);
+ // 进入到这里代表没有权限.
+
+ }
+ }
+ String tmpList[] = new String[toApplyList.size()];
+ if (!toApplyList.isEmpty()) {
+ ActivityCompat.requestPermissions(this, toApplyList.toArray(tmpList), 123);
+ }
+
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
+ // 此处为android 6.0以上动态授权的回调,用户自行实现。
+ }
+
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/mini/ActivityMiniUnit.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/mini/ActivityMiniUnit.java
new file mode 100644
index 0000000..d77b16d
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/mini/ActivityMiniUnit.java
@@ -0,0 +1,269 @@
+package com.baidu.aip.asrwakeup3.core.mini;
+
+import android.Manifest;
+import android.content.pm.PackageManager;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.app.ActivityCompat;
+import androidx.core.content.ContextCompat;
+
+import com.baidu.aip.asrwakeup3.core.R;
+import com.baidu.aip.asrwakeup3.core.util.AuthUtil;
+import com.baidu.speech.EventListener;
+import com.baidu.speech.EventManager;
+import com.baidu.speech.EventManagerFactory;
+import com.baidu.speech.asr.SpeechConstant;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * 集成文档: http://ai.baidu.com/docs#/ASR-Android-SDK/top 集成指南一节
+ * demo目录下doc_integration_DOCUMENT
+ * ASR-INTEGRATION-helloworld ASR集成指南-集成到helloworld中 对应 ActivityMiniRecog
+ * ASR-INTEGRATION-TTS-DEMO ASR集成指南-集成到合成DEMO中 对应 ActivityRecog
+ */
+
+public class ActivityMiniUnit extends AppCompatActivity implements EventListener {
+ protected TextView txtLog;
+ protected TextView txtResult;
+ protected Button btn;
+ protected Button stopBtn;
+ private static String DESC_TEXT =
+ "UNIT 2.0为自定义语义解析+多轮会话等功能。语音SDK使用时,仅省去一次http请求。(语音SDK调用Unit实际效果)=(语音识别后的文字+Unit http请求结果)\n\n"+
+ "精简版Unit,带有SDKUnit功能的最少代码,仅仅展示如何调用,\n" +
+ "结果返回‘我不知道应该怎么答复您。’表示测试成功。 \n" +
+ "上述句子测试成功后,Unit 2.0具体功能请通过Unit的QQ群,工单,论坛咨询。语音相关反馈方式不回复Unit相关问题。https://ai.baidu.com/unit/home";
+
+ private EventManager asr;
+
+ private boolean logTime = true;
+
+ protected boolean enableOffline = false; // 测试Unit 2.0 功能,必须一直联网
+
+ private String BOT_ID = "26435"; // 修改你自己的AppId AppKey AppSecret后,换成你自己的BOT_ID测试
+
+ /**
+ * 基于SDK集成2.2 发送开始事件
+ * 点击开始按钮
+ * 测试参数填在这里
+ */
+ private void start() {
+ txtLog.setText("");
+ Map params = AuthUtil.getParam();
+ String event = null;
+ event = SpeechConstant.ASR_START; // 替换成测试的event
+
+ if (enableOffline) {
+ params.put(SpeechConstant.DECODER, 2);
+ }
+ // 基于SDK集成2.1 设置识别参数
+ params.put(SpeechConstant.ACCEPT_AUDIO_VOLUME, false);
+ params.put(SpeechConstant.PID, 15374); // 或 19364 Unit 2.0 固定pid,仅支持中文普通话
+ // params.put(SpeechConstant.NLU, "enable");
+ // params.put(SpeechConstant.VAD_ENDPOINT_TIMEOUT, 0); // 长语音
+ // params.put(SpeechConstant.IN_FILE, "res:///com/baidu/android/voicedemo/16k_test.pcm");
+ // params.put(SpeechConstant.VAD, SpeechConstant.VAD_DNN);
+
+ // 请先使用如‘在线识别’界面测试和生成识别参数。 params同ActivityRecog类中myRecognizer.start(params);
+ params.put(SpeechConstant.BOT_SESSION_LIST, unitParams());
+ // 复制此段可以自动检测错误
+ (new AutoCheck(getApplicationContext(), new Handler() {
+ public void handleMessage(Message msg) {
+ if (msg.what == 100) {
+ AutoCheck autoCheck = (AutoCheck) msg.obj;
+ synchronized (autoCheck) {
+ String message = autoCheck.obtainErrorMessage(); // autoCheck.obtainAllMessage();
+ txtLog.append(message + "\n");
+ ; // 可以用下面一行替代,在logcat中查看代码
+ // Log.w("AutoCheckMessage", message);
+ }
+ }
+ }
+ },enableOffline)).checkAsr(params);
+ String json = null; // 可以替换成自己的json
+ json = new JSONObject(params).toString(); // 这里可以替换成你需要测试的json
+ asr.send(event, json, null, 0, 0);
+ printLog("输入参数:" + json);
+ }
+
+ /**
+ * 点击停止按钮
+ * 基于SDK集成4.1 发送停止事件
+ */
+ private void stop() {
+ printLog("停止识别:ASR_STOP");
+ asr.send(SpeechConstant.ASR_STOP, null, null, 0, 0); //
+ }
+
+
+ /**
+ * enableOffline设为true时,在onCreate中调用
+ * 基于SDK离线命令词1.4 加载离线资源(离线时使用)
+ */
+ private void loadOfflineEngine() {
+ Map params = new LinkedHashMap();
+ params.put(SpeechConstant.DECODER, 2);
+ params.put(SpeechConstant.ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH, "assets://baidu_speech_grammar.bsg");
+ asr.send(SpeechConstant.ASR_KWS_LOAD_ENGINE, new JSONObject(params).toString(), null, 0, 0);
+ }
+
+ /**
+ * enableOffline为true时,在onDestory中调用,与loadOfflineEngine对应
+ * 基于SDK集成5.1 卸载离线资源步骤(离线时使用)
+ */
+ private void unloadOfflineEngine() {
+ asr.send(SpeechConstant.ASR_KWS_UNLOAD_ENGINE, null, null, 0, 0); //
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.common_mini);
+ initView();
+ initPermission();
+ // 基于sdk集成1.1 初始化EventManager对象
+ asr = EventManagerFactory.create(this, "asr");
+ // 基于sdk集成1.3 注册自己的输出事件类
+ asr.registerListener(this); // EventListener 中 onEvent方法
+ btn.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ start();
+ }
+ });
+ stopBtn.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ stop();
+ }
+ });
+ if (enableOffline) {
+ loadOfflineEngine(); // 测试离线命令词请开启, 测试 ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH 参数时开启
+ }
+ }
+
+ @Override
+ protected void onPause(){
+ super.onPause();
+ asr.send(SpeechConstant.ASR_CANCEL, "{}", null, 0, 0);
+ Log.i("ActivityMiniRecog","On pause");
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ // 基于SDK集成4.2 发送取消事件
+ asr.send(SpeechConstant.ASR_CANCEL, "{}", null, 0, 0);
+ if (enableOffline) {
+ unloadOfflineEngine(); // 测试离线命令词请开启, 测试 ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH 参数时开启
+ }
+
+ // 基于SDK集成5.2 退出事件管理器
+ // 必须与registerListener成对出现,否则可能造成内存泄露
+ asr.unregisterListener(this);
+ }
+
+ /**
+ * Unit 2.0具体功能请通过Unit的QQ群,工单,论坛咨询。语音相关反馈方式不回复Unit相关问题
+ * @return
+ */
+ private JSONArray unitParams() {
+ JSONArray json = new JSONArray();
+ try {
+ JSONObject bot = new JSONObject();
+ bot.put("bot_id",BOT_ID);
+ bot.put("bot_session_id","");
+ bot.put("bot_session","");
+ json.put(bot);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return json;
+ }
+
+ // 基于sdk集成1.2 自定义输出事件类 EventListener 回调方法
+ // 基于SDK集成3.1 开始回调事件
+ @Override
+ public void onEvent(String name, String params, byte[] data, int offset, int length) {
+ String logTxt = "name: " + name;
+
+
+ if (params != null && !params.isEmpty()) {
+ logTxt += " ;params :" + params;
+ }
+ if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL)) {
+ if (params != null && params.contains("\"nlu_result\"")) {
+ if (length > 0 && data.length > 0) {
+ logTxt += ", 语义解析结果:" + new String(data, offset, length);
+ }
+ }
+ } else if (data != null) {
+ logTxt += " ;data length=" + data.length;
+ }
+ printLog(logTxt);
+ }
+
+ private void printLog(String text) {
+ if (logTime) {
+ text += " ;time=" + System.currentTimeMillis();
+ }
+ text += "\n";
+ Log.i(getClass().getName(), text);
+ txtLog.append(text + "\n");
+ }
+
+
+ private void initView() {
+ txtResult = (TextView) findViewById(R.id.txtResult);
+ txtLog = (TextView) findViewById(R.id.txtLog);
+ btn = (Button) findViewById(R.id.btn);
+ stopBtn = (Button) findViewById(R.id.btn_stop);
+ txtLog.setText(DESC_TEXT + "\n");
+ }
+
+ /**
+ * android 6.0 以上需要动态申请权限
+ */
+ private void initPermission() {
+ String permissions[] = {Manifest.permission.RECORD_AUDIO,
+ Manifest.permission.ACCESS_NETWORK_STATE,
+ Manifest.permission.INTERNET,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE
+ };
+
+ ArrayList toApplyList = new ArrayList();
+
+ for (String perm : permissions) {
+ if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(this, perm)) {
+ toApplyList.add(perm);
+ // 进入到这里代表没有权限.
+
+ }
+ }
+ String tmpList[] = new String[toApplyList.size()];
+ if (!toApplyList.isEmpty()) {
+ ActivityCompat.requestPermissions(this, toApplyList.toArray(tmpList), 123);
+ }
+
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
+ // 此处为android 6.0以上动态授权的回调,用户自行实现。
+ }
+
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/mini/ActivityMiniWakeUp.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/mini/ActivityMiniWakeUp.java
new file mode 100644
index 0000000..e923a2f
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/mini/ActivityMiniWakeUp.java
@@ -0,0 +1,166 @@
+package com.baidu.aip.asrwakeup3.core.mini;
+
+import android.Manifest;
+import android.content.pm.PackageManager;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.app.ActivityCompat;
+import androidx.core.content.ContextCompat;
+
+import com.baidu.aip.asrwakeup3.core.R;
+import com.baidu.aip.asrwakeup3.core.inputstream.InFileStream;
+import com.baidu.aip.asrwakeup3.core.util.AuthUtil;
+import com.baidu.speech.EventListener;
+import com.baidu.speech.EventManager;
+import com.baidu.speech.EventManagerFactory;
+import com.baidu.speech.asr.SpeechConstant;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * Created by fujiayi on 2017/8/15.
+ */
+
+public class ActivityMiniWakeUp extends AppCompatActivity implements EventListener {
+ protected TextView txtLog;
+ protected TextView txtResult;
+ protected Button btn;
+ protected Button stopBtn;
+ private static String DESC_TEXT = "精简版唤醒,带有SDK唤醒运行的最少代码,仅仅展示如何调用,\n" +
+ "也可以用来反馈测试SDK输入参数及输出回调。\n" +
+ "本示例需要自行根据文档填写参数,可以使用之前唤醒示例中的日志中的参数。\n" +
+ "需要完整版请参见之前的唤醒示例。\n\n" +
+ "唤醒词是纯离线功能,需要获取正式授权文件(与离线命令词的正式授权文件是同一个)。 第一次联网使用唤醒词功能自动获取正式授权文件。之后可以断网测试\n" +
+ "请说“小度你好”或者 “百度一下”\n\n";
+
+ private EventManager wakeup;
+
+ private boolean logTime = true;
+
+ /**
+ * 测试参数填在这里
+ * 基于SDK唤醒词集成第2.1 设置唤醒的输入参数
+ */
+ private void start() {
+ txtLog.setText("");
+ // 基于SDK唤醒词集成第2.1 设置唤醒的输入参数
+ Map params = AuthUtil.getParam();
+ params.put(SpeechConstant.ACCEPT_AUDIO_VOLUME, false);
+ params.put(SpeechConstant.WP_WORDS_FILE, "assets:///WakeUp.bin");
+ // "assets:///WakeUp.bin" 表示WakeUp.bin文件定义在assets目录下
+ InFileStream.setContext(this);
+ String json = null; // 这里可以替换成你需要测试的json
+ json = new JSONObject(params).toString();
+ wakeup.send(SpeechConstant.WAKEUP_START, json, null, 0, 0);
+ printLog("输入参数:" + json);
+ }
+
+ // 基于SDK唤醒词集成第4.1 发送停止事件
+ private void stop() {
+ wakeup.send(SpeechConstant.WAKEUP_STOP, null, null, 0, 0); //
+ }
+
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.common_mini);
+ initView();
+ initPermission();
+ // 基于SDK唤醒词集成1.1 初始化EventManager
+ wakeup = EventManagerFactory.create(this, "wp");
+ // 基于SDK唤醒词集成1.3 注册输出事件
+ wakeup.registerListener(this); // EventListener 中 onEvent方法
+ btn.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ start();
+ }
+ });
+ stopBtn.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ stop();
+ }
+ });
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ wakeup.send(SpeechConstant.WAKEUP_STOP, "{}", null, 0, 0);
+ }
+
+ // 基于SDK唤醒词集成1.2 自定义输出事件类 EventListener 回调方法
+ // 基于SDK唤醒3.1 开始回调事件
+ @Override
+ public void onEvent(String name, String params, byte[] data, int offset, int length) {
+ String logTxt = "name: " + name;
+ if (params != null && !params.isEmpty()) {
+ logTxt += " ;params :" + params;
+ } else if (data != null) {
+ logTxt += " ;data length=" + data.length;
+ }
+ printLog(logTxt);
+ }
+
+ private void printLog(String text) {
+ if (logTime) {
+ text += " ;time=" + System.currentTimeMillis();
+ }
+ text += "\n";
+ Log.i(getClass().getName(), text);
+ txtLog.append(text + "\n");
+ }
+
+
+ private void initView() {
+ txtResult = (TextView) findViewById(R.id.txtResult);
+ txtLog = (TextView) findViewById(R.id.txtLog);
+ btn = (Button) findViewById(R.id.btn);
+ stopBtn = (Button) findViewById(R.id.btn_stop);
+ txtLog.setText(DESC_TEXT + "\n");
+ }
+
+ /**
+ * android 6.0 以上需要动态申请权限
+ */
+ private void initPermission() {
+ String[] permissions = {Manifest.permission.RECORD_AUDIO,
+ Manifest.permission.ACCESS_NETWORK_STATE,
+ Manifest.permission.INTERNET,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE
+ };
+
+ ArrayList toApplyList = new ArrayList();
+
+ for (String perm : permissions) {
+ if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(this, perm)) {
+ toApplyList.add(perm);
+ // 进入到这里代表没有权限.
+
+ }
+ }
+ String[] tmpList = new String[toApplyList.size()];
+ if (!toApplyList.isEmpty()) {
+ ActivityCompat.requestPermissions(this, toApplyList.toArray(tmpList), 123);
+ }
+
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
+ // 此处为android 6.0以上动态授权的回调,用户自行实现。
+ }
+
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/mini/AutoCheck.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/mini/AutoCheck.java
new file mode 100644
index 0000000..9de1747
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/mini/AutoCheck.java
@@ -0,0 +1,472 @@
+package com.baidu.aip.asrwakeup3.core.mini;
+
+import android.Manifest;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+
+import androidx.core.content.ContextCompat;
+
+import com.baidu.speech.asr.SpeechConstant;
+import org.json.JSONObject;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.TreeSet;
+
+import javax.net.ssl.HttpsURLConnection;
+
+public class AutoCheck {
+ public static final boolean isOnlineLited = false; // 是否只需要是纯在线识别功能
+ private LinkedHashMap checks;
+
+ private Context context;
+ private Handler handler;
+
+ private boolean hasError;
+ private boolean enableOffline;
+ private boolean isFinished = false;
+
+ private String name;
+
+ private static final String TAG = "AutoCheck";
+
+ public AutoCheck(Context context, final Handler handler, boolean enableOffline) {
+ this.context = context;
+ checks = new LinkedHashMap<>();
+ this.handler = handler;
+ this.enableOffline = enableOffline;
+ }
+
+ public void checkAsr(final Map params) {
+ Thread t = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ AutoCheck obj = checkAsrInternal(params);
+ name = "识别";
+ synchronized (obj) { // 偶发,同步线程信息
+ isFinished = true;
+ Message msg = handler.obtainMessage(100, obj);
+ handler.sendMessage(msg);
+ }
+ }
+ });
+ t.start();
+ }
+
+ public String obtainErrorMessage() {
+ PrintConfig config = new PrintConfig();
+ return formatString(config);
+ }
+
+ public String obtainDebugMessage() {
+ PrintConfig config = new PrintConfig();
+ config.withInfo = true;
+ return formatString(config);
+ }
+
+ public String obtainAllMessage() {
+ PrintConfig config = new PrintConfig();
+ config.withLog = true;
+ config.withInfo = true;
+ config.withLogOnSuccess = true;
+ return formatString(config);
+ }
+
+ private String formatString(PrintConfig config) {
+ StringBuilder sb = new StringBuilder();
+ hasError = false;
+
+ for (HashMap.Entry entry : checks.entrySet()) {
+ Check check = entry.getValue();
+ String testName = entry.getKey();
+ if (check.hasError()) {
+ if (!hasError) {
+ hasError = true;
+ }
+
+ sb.append("【错误】【").append(testName).append(" 】 ").append(check.getErrorMessage()).append("\n");
+ Log.e("AutoCheck", sb.toString());
+ if (check.hasFix()) {
+ sb.append("【修复方法】【").append(testName).append(" 】 ").append(check.getFixMessage()).append("\n");
+ }
+ } else if (config.withEachCheckInfo) {
+ sb.append("【无报错】【").append(testName).append(" 】 ").append("\n");
+ }
+ if (config.withInfo && check.hasInfo()) {
+ sb.append("【请手动检查】【").append(testName).append("】 ").append(check.getInfoMessage()).append("\n");
+ }
+ if (config.withLog && (config.withLogOnSuccess || hasError) && check.hasLog()) {
+ sb.append("【log】:" + check.getLogMessage()).append("\n");
+ }
+ }
+ if (!hasError) {
+ sb.append("【" + name + "】集成自动排查工具: 恭喜没有检测到任何问题\n");
+ }
+ return sb.toString();
+ }
+
+ private AutoCheck checkAsrInternal(Map params) {
+ commonSetting(params);
+ checks.put("外部音频文件存在校验", new FileCheck(context, params, SpeechConstant.IN_FILE));
+ checks.put("离线命令词及本地语义bsg文件存在校验",
+ new FileCheck(context, params, SpeechConstant.ASR_OFFLINE_ENGINE_GRAMMER_FILE_PATH));
+ for (Map.Entry e : checks.entrySet()) {
+ Check check = e.getValue();
+ check.check();
+ if (check.hasError()) {
+ break;
+ }
+ }
+ return this;
+ }
+
+ private void commonSetting(Map params) {
+ checks.put("检查申请的Android权限", new PermissionCheck(context));
+ checks.put("检查so文件是否存在", new JniCheck(context));
+ AppInfoCheck infoCheck = null;
+ try {
+ infoCheck = new AppInfoCheck(context, params);
+ checks.put("检查AppId AppKey SecretKey", infoCheck);
+ } catch (PackageManager.NameNotFoundException e) {
+ e.printStackTrace();
+ Log.e(TAG, "检查AppId AppKey SecretKey 错误", e);
+ return;
+ }
+ if (enableOffline) {
+ checks.put("检查包名", new ApplicationIdCheck(context, infoCheck.appId));
+ }
+
+ }
+
+ private static class PrintConfig {
+ public boolean withEachCheckInfo = false;
+ public boolean withInfo = false;
+ public boolean withLog = false;
+ public boolean withLogOnSuccess = false;
+ }
+
+
+ private static class PermissionCheck extends Check {
+ private Context context;
+
+ public PermissionCheck(Context context) {
+ this.context = context;
+ }
+
+ @Override
+ public void check() {
+ String[] permissions = {
+ Manifest.permission.RECORD_AUDIO,
+ Manifest.permission.ACCESS_NETWORK_STATE,
+ Manifest.permission.INTERNET,
+ // Manifest.permission.WRITE_EXTERNAL_STORAGE,
+ };
+
+ ArrayList toApplyList = new ArrayList();
+ for (String perm : permissions) {
+ if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(context, perm)) {
+ toApplyList.add(perm);
+ // 进入到这里代表没有权限.
+ }
+ }
+ if (!toApplyList.isEmpty()) {
+ errorMessage = "缺少权限:" + toApplyList;
+ fixMessage = "请从AndroidManifest.xml复制相关权限";
+ }
+ }
+ }
+
+ private static class JniCheck extends Check {
+ private Context context;
+
+ private String[] soNames;
+
+ public JniCheck(Context context) {
+ this.context = context;
+ if (isOnlineLited) {
+ soNames = new String[]{"libBaiduSpeechSDK.so", "libvad.dnn.so"};
+ } else {
+ soNames = new String[]{"libBaiduSpeechSDK.so", "libvad.dnn.so",
+ "libbd_easr_s1_merge_normal_20151216.dat.so", "libbdEASRAndroid.so",
+ "libbdSpilWakeup.so"};
+ }
+ }
+
+ @Override
+ public void check() {
+ String path = context.getApplicationInfo().nativeLibraryDir;
+ appendLogMessage("Jni so文件目录 " + path);
+ File[] files = new File(path).listFiles();
+ TreeSet set = new TreeSet<>();
+ if (files != null) {
+ for (File file : files) {
+ set.add(file.getName());
+ }
+ }
+ // String debugMessage = "Jni目录内文件: " + set.toString();
+ // boolean isSuccess = true;
+ for (String name : soNames) {
+ if (!set.contains(name)) {
+ errorMessage = "Jni目录" + path + " 缺少so文件:" + name + ", 该目录文件列表: " + set.toString();
+ fixMessage = "如果您的app内没有其它so文件,请复制demo里的src/main/jniLibs至同名目录。"
+ + " 如果app内有so文件,请合并目录放一起(注意目录取交集,多余的目录删除)。";
+ break;
+ }
+ }
+ }
+ }
+
+ private static class AppInfoCheck extends Check {
+ private String appId;
+ private String appKey;
+ private String secretKey;
+
+ public AppInfoCheck(Context context, Map params) throws PackageManager.NameNotFoundException {
+
+ if (params.get(SpeechConstant.APP_ID) != null) {
+ appId = params.get(SpeechConstant.APP_ID).toString();
+ }
+ if (params.get(SpeechConstant.APP_KEY) != null) {
+ appKey = params.get(SpeechConstant.APP_KEY).toString();
+ }
+
+ if (params.get(SpeechConstant.SECRET) != null) {
+ secretKey = params.get(SpeechConstant.SECRET).toString();
+ }
+ }
+
+
+ public void check() {
+ do {
+ appendLogMessage("try to check appId " + appId + " ,appKey=" + appKey + " ,secretKey" + secretKey);
+ if (appId == null || appId.isEmpty()) {
+ errorMessage = "appId 为空";
+ fixMessage = "填写appID";
+ break;
+ }
+ if (appKey == null || appKey.isEmpty()) {
+ errorMessage = "appKey 为空";
+ fixMessage = "填写appID";
+ break;
+ }
+ if (secretKey == null || secretKey.isEmpty()) {
+ errorMessage = "secretKey 为空";
+ fixMessage = "secretKey";
+ break;
+ }
+
+
+ try {
+ checkOnline();
+ } catch (UnknownHostException e) {
+ infoMessage = "无网络或者网络不连通,忽略检测 : " + e.getMessage();
+ } catch (Exception e) {
+ errorMessage = e.getClass().getCanonicalName() + ":" + e.getMessage();
+ fixMessage = " 重新检测appId, appKey, appSecret是否正确";
+ }
+ } while (false);
+ }
+
+ public void checkOnline() throws Exception {
+ String urlpath = "https://openapi.baidu.com/oauth/2.0/token?client_id="
+ + appKey + "&client_secret=" + secretKey + "&grant_type=client_credentials";
+ Log.i("AutoCheck", "Url is " + urlpath);
+ URL url = new URL(urlpath);
+ HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
+ conn.setRequestMethod("GET");
+ conn.setConnectTimeout(1000);
+ InputStream is = conn.getInputStream();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+ StringBuilder result = new StringBuilder();
+ String line = "";
+ do {
+ line = reader.readLine();
+ if (line != null) {
+ result.append(line);
+ }
+ } while (line != null);
+ String res = result.toString();
+ if (!res.contains("audio_voice_assistant_get")) {
+ errorMessage = "appid:" + appId + ",没有audio_voice_assistant_get 权限,请在网页上开通\"语音识别\"能力";
+ fixMessage = "secretKey";
+ return;
+ }
+ appendLogMessage("openapi return " + res);
+ JSONObject jsonObject = new JSONObject(res);
+ String error = jsonObject.optString("error");
+ if (error != null && !error.isEmpty()) {
+ errorMessage = "appkey secretKey 错误" + ", error:" + error + ", json is" + result;
+ fixMessage = " 重新检测appId对应的 appKey, appSecret是否正确";
+ return;
+ }
+ String token = jsonObject.getString("access_token");
+ if (token == null || !token.endsWith("-" + appId)) {
+ errorMessage = "appId 与 appkey及 appSecret 不一致。appId = " + appId + " ,token = " + token;
+ fixMessage = " 重新检测appId对应的 appKey, appSecret是否正确";
+ }
+ }
+ }
+
+ private static class ApplicationIdCheck extends Check {
+
+ private String appId;
+ private Context context;
+
+ public ApplicationIdCheck(Context context, String appId) {
+ this.appId = appId;
+ this.context = context;
+ }
+
+ @Override
+ public void check() {
+ infoMessage = "如果您集成过程中遇见离线命令词或者唤醒初始化问题,请检查网页上appId:" + appId
+ + " 应用填写了Android包名:"
+ + getApplicationId();
+ }
+
+ private String getApplicationId() {
+ return context.getPackageName();
+ }
+ }
+
+ private static class FileCheck extends Check {
+ private Map params;
+ private String key;
+ private Context context;
+ private boolean allowRes = false;
+ private boolean allowAssets = true;
+
+ public FileCheck(Context context, Map params, String key) {
+ this.context = context;
+ this.params = params;
+ this.key = key;
+ if (key.equals(SpeechConstant.IN_FILE)) {
+ allowRes = true;
+ allowAssets = false;
+ }
+ }
+
+ @Override
+ public void check() {
+ if (!params.containsKey(key)) {
+ return;
+ }
+ String value = params.get(key).toString();
+ if (allowAssets) {
+ int len = "assets".length();
+ int totalLen = len + ":///".length();
+ if (value.startsWith("assets")) {
+ String filename = value.substring(totalLen);
+ if (!":///".equals(value.substring(len, totalLen)) || filename.isEmpty()) {
+ errorMessage = "参数:" + key + "格式错误:" + value;
+ fixMessage = "修改成" + "assets:///sdcard/xxxx.yyy";
+ }
+ try {
+ context.getAssets().open(filename);
+ } catch (IOException e) {
+ errorMessage = "assets 目录下,文件不存在:" + filename;
+ fixMessage = "demo的assets目录是:src/main/assets";
+ e.printStackTrace();
+ }
+ appendLogMessage("assets 检验完毕:" + filename);
+ }
+ }
+ if (allowRes) {
+ int len = "res".length();
+ int totalLen = len + ":///".length();
+ if (value.startsWith("res")) {
+ String filename = value.substring(totalLen);
+ if (!":///".equals(value.substring(len, totalLen)) || filename.isEmpty()) {
+ errorMessage = "参数:" + key + "格式错误:" + value;
+ fixMessage = "修改成" + "res:///com/baidu/android/voicedemo/16k_test.pcm";
+ }
+ InputStream is = getClass().getClassLoader().getResourceAsStream(filename);
+ if (is == null) {
+ errorMessage = "res,文件不存在:" + filename;
+ fixMessage = "demo的res目录是:app/src/main/resources";
+ } else {
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ appendLogMessage("res 检验完毕:" + filename);
+ }
+ }
+ if (value.startsWith("/")) {
+ if (!new File(value).canRead()) {
+ errorMessage = "文件不存在:" + value;
+ fixMessage = "请查看文件是否存在";
+ }
+ appendLogMessage("文件路径 检验完毕:" + value);
+ }
+ }
+ }
+
+ private abstract static class Check {
+ protected String errorMessage = null;
+
+ protected String fixMessage = null;
+
+ protected String infoMessage = null;
+
+ protected StringBuilder logMessage;
+
+ public Check() {
+ logMessage = new StringBuilder();
+ }
+
+ public abstract void check();
+
+ public boolean hasError() {
+ return errorMessage != null;
+ }
+
+ public boolean hasFix() {
+ return fixMessage != null;
+ }
+
+ public boolean hasInfo() {
+ return infoMessage != null;
+ }
+
+ public boolean hasLog() {
+ return !logMessage.toString().isEmpty();
+ }
+
+ public void appendLogMessage(String message) {
+ logMessage.append(message + "\n");
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ public String getFixMessage() {
+ return fixMessage;
+ }
+
+ public String getInfoMessage() {
+ return infoMessage;
+ }
+
+ public String getLogMessage() {
+ return logMessage.toString();
+ }
+ }
+}
+
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/IStatus.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/IStatus.java
new file mode 100644
index 0000000..29d63fe
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/IStatus.java
@@ -0,0 +1,24 @@
+package com.baidu.aip.asrwakeup3.core.recog;
+
+/**
+ * Created by fujiayi on 2017/6/14.
+ */
+
+public interface IStatus {
+
+ int STATUS_NONE = 2;
+
+ int STATUS_READY = 3;
+ int STATUS_SPEAKING = 4;
+ int STATUS_RECOGNITION = 5;
+
+ int STATUS_FINISHED = 6;
+ int STATUS_LONG_SPEECH_FINISHED = 7;
+ int STATUS_STOPPED = 10;
+
+ int STATUS_WAITING_READY = 8001;
+ int WHAT_MESSAGE_STATUS = 9001;
+
+ int STATUS_WAKEUP_SUCCESS = 7001;
+ int STATUS_WAKEUP_EXIT = 7003;
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/MyRecognizer.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/MyRecognizer.java
new file mode 100644
index 0000000..1dd4650
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/MyRecognizer.java
@@ -0,0 +1,142 @@
+package com.baidu.aip.asrwakeup3.core.recog;
+
+import android.content.Context;
+import com.baidu.aip.asrwakeup3.core.util.MyLogger;
+import com.baidu.speech.EventListener;
+import com.baidu.speech.EventManager;
+import com.baidu.speech.EventManagerFactory;
+import com.baidu.speech.asr.SpeechConstant;
+import org.json.JSONObject;
+import com.baidu.aip.asrwakeup3.core.recog.listener.IRecogListener;
+import com.baidu.aip.asrwakeup3.core.recog.listener.RecogEventAdapter;
+
+import java.util.Map;
+
+/**
+ * Created by fujiayi on 2017/6/13.
+ * EventManager内的方法如send 都可以在主线程中进行,SDK中做过处理
+ */
+
+public class MyRecognizer {
+ /**
+ * SDK 内部核心 EventManager 类
+ */
+ private EventManager asr;
+
+ // SDK 内部核心 事件回调类, 用于开发者写自己的识别回调逻辑
+ private EventListener eventListener;
+
+ // 是否加载离线资源
+ private static boolean isOfflineEngineLoaded = false;
+
+ // 未release前,只能new一个
+ private static volatile boolean isInited = false;
+
+ private static final String TAG = "MyRecognizer";
+
+ /**
+ * 初始化
+ *
+ * @param context
+ * @param recogListener 将EventListener结果做解析的DEMO回调。使用RecogEventAdapter 适配EventListener
+ */
+ public MyRecognizer(Context context, IRecogListener recogListener) {
+ this(context, new RecogEventAdapter(recogListener));
+ }
+
+ /**
+ * 初始化 提供 EventManagerFactory需要的Context和EventListener
+ *
+ * @param context
+ * @param eventListener 识别状态和结果回调
+ */
+ public MyRecognizer(Context context, EventListener eventListener) {
+ if (isInited) {
+ MyLogger.error(TAG, "还未调用release(),请勿新建一个新类");
+ throw new RuntimeException("还未调用release(),请勿新建一个新类");
+ }
+ isInited = true;
+ this.eventListener = eventListener;
+ // SDK集成步骤 初始化asr的EventManager示例,多次得到的类,只能选一个使用
+ asr = EventManagerFactory.create(context, "asr");
+ // SDK集成步骤 设置回调event, 识别引擎会回调这个类告知重要状态和识别结果
+ asr.registerListener(eventListener);
+ }
+
+
+ /**
+ * 离线命令词,在线不需要调用
+ *
+ * @param params 离线命令词加载参数,见文档“ASR_KWS_LOAD_ENGINE 输入事件参数”
+ */
+ public void loadOfflineEngine(Map params) {
+ String json = new JSONObject(params).toString();
+ MyLogger.info(TAG + ".Debug", "离线命令词初始化参数(反馈请带上此行日志):" + json);
+ // SDK集成步骤(可选)加载离线命令词(离线时使用)
+ asr.send(SpeechConstant.ASR_KWS_LOAD_ENGINE, json, null, 0, 0);
+ isOfflineEngineLoaded = true;
+ }
+
+ /**
+ * @param params
+ */
+ public void start(Map params) {
+ if (!isInited) {
+ throw new RuntimeException("release() was called");
+ }
+ // SDK集成步骤 拼接识别参数
+ String json = new JSONObject(params).toString();
+ MyLogger.info(TAG + ".Debug", "识别参数(反馈请带上此行日志)" + json);
+ asr.send(SpeechConstant.ASR_START, json, null, 0, 0);
+ }
+
+
+ /**
+ * 提前结束录音等待识别结果。
+ */
+ public void stop() {
+ MyLogger.info(TAG, "停止录音");
+ // SDK 集成步骤(可选)停止录音
+ if (!isInited) {
+ throw new RuntimeException("release() was called");
+ }
+ asr.send(SpeechConstant.ASR_STOP, "{}", null, 0, 0);
+ }
+
+ /**
+ * 取消本次识别,取消后将立即停止不会返回识别结果。
+ * cancel 与stop的区别是 cancel在stop的基础上,完全停止整个识别流程,
+ */
+ public void cancel() {
+ MyLogger.info(TAG, "取消识别");
+ if (!isInited) {
+ throw new RuntimeException("release() was called");
+ }
+ // SDK集成步骤 (可选) 取消本次识别
+ asr.send(SpeechConstant.ASR_CANCEL, "{}", null, 0, 0);
+ }
+
+ public void release() {
+ if (asr == null) {
+ return;
+ }
+ cancel();
+ if (isOfflineEngineLoaded) {
+ // SDK集成步骤 如果之前有调用过 加载离线命令词,这里要对应释放
+ asr.send(SpeechConstant.ASR_KWS_UNLOAD_ENGINE, null, null, 0, 0);
+ isOfflineEngineLoaded = false;
+ }
+ // SDK 集成步骤(可选),卸载listener
+ asr.unregisterListener(eventListener);
+ asr = null;
+ isInited = false;
+ }
+
+ public void setEventListener(IRecogListener recogListener) {
+ if (!isInited) {
+ throw new RuntimeException("release() was called");
+ }
+ this.eventListener = new RecogEventAdapter(recogListener);
+ asr.registerListener(eventListener);
+ }
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/RecogResult.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/RecogResult.java
new file mode 100644
index 0000000..c36c8a6
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/RecogResult.java
@@ -0,0 +1,134 @@
+package com.baidu.aip.asrwakeup3.core.recog;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Created by fujiayi on 2017/6/24.
+ */
+public class RecogResult {
+ private static final int ERROR_NONE = 0;
+
+ private String origalJson;
+ private String[] resultsRecognition;
+ private String origalResult;
+ private String sn; // 日志id, 请求有问题请提问带上sn
+ private String desc;
+ private String resultType;
+ private int error = -1;
+ private int subError = -1;
+
+ public static RecogResult parseJson(String jsonStr) {
+ RecogResult result = new RecogResult();
+ result.setOrigalJson(jsonStr);
+ try {
+ JSONObject json = new JSONObject(jsonStr);
+ int error = json.optInt("error");
+ int subError = json.optInt("sub_error");
+ result.setError(error);
+ result.setDesc(json.optString("desc"));
+ result.setResultType(json.optString("result_type"));
+ result.setSubError(subError);
+ if (error == ERROR_NONE) {
+ result.setOrigalResult(json.getString("origin_result"));
+ JSONArray arr = json.optJSONArray("results_recognition");
+ if (arr != null) {
+ int size = arr.length();
+ String[] recogs = new String[size];
+ for (int i = 0; i < size; i++) {
+ recogs[i] = arr.getString(i);
+ }
+ result.setResultsRecognition(recogs);
+ }
+
+
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+
+ return result;
+ }
+
+ public boolean hasError() {
+ return error != ERROR_NONE;
+ }
+
+ public boolean isFinalResult() {
+ return "final_result".equals(resultType);
+ }
+
+
+ public boolean isPartialResult() {
+ return "partial_result".equals(resultType);
+ }
+
+ public boolean isNluResult() {
+ return "nlu_result".equals(resultType);
+ }
+
+ public String getOrigalJson() {
+ return origalJson;
+ }
+
+ public void setOrigalJson(String origalJson) {
+ this.origalJson = origalJson;
+ }
+
+ public String[] getResultsRecognition() {
+ return resultsRecognition;
+ }
+
+ public void setResultsRecognition(String[] resultsRecognition) {
+ this.resultsRecognition = resultsRecognition;
+ }
+
+ public String getSn() {
+ return sn;
+ }
+
+ public void setSn(String sn) {
+ this.sn = sn;
+ }
+
+ public int getError() {
+ return error;
+ }
+
+ public void setError(int error) {
+ this.error = error;
+ }
+
+ public String getDesc() {
+ return desc;
+ }
+
+ public void setDesc(String desc) {
+ this.desc = desc;
+ }
+
+ public String getOrigalResult() {
+ return origalResult;
+ }
+
+ public void setOrigalResult(String origalResult) {
+ this.origalResult = origalResult;
+ }
+
+ public String getResultType() {
+ return resultType;
+ }
+
+ public void setResultType(String resultType) {
+ this.resultType = resultType;
+ }
+
+ public int getSubError() {
+ return subError;
+ }
+
+ public void setSubError(int subError) {
+ this.subError = subError;
+ }
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/listener/ChainRecogListener.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/listener/ChainRecogListener.java
new file mode 100644
index 0000000..73156d8
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/listener/ChainRecogListener.java
@@ -0,0 +1,146 @@
+package com.baidu.aip.asrwakeup3.core.recog.listener;
+
+
+import com.baidu.aip.asrwakeup3.core.recog.RecogResult;
+
+import java.util.ArrayList;
+
+/**
+ * Created by fujiayi on 2017/10/18.
+ */
+
+public class ChainRecogListener implements IRecogListener {
+
+ private ArrayList listeners;
+
+ public ChainRecogListener() {
+ listeners = new ArrayList();
+ }
+
+ public void addListener(IRecogListener listener) {
+ listeners.add(listener);
+ }
+
+ /**
+ * ASR_START 输入事件调用后,引擎准备完毕
+ */
+ @Override
+ public void onAsrReady() {
+ for (IRecogListener listener : listeners) {
+ listener.onAsrReady();
+ }
+ }
+
+ /**
+ * onAsrReady后检查到用户开始说话
+ */
+ @Override
+ public void onAsrBegin() {
+ for (IRecogListener listener : listeners) {
+ listener.onAsrBegin();
+ }
+ }
+
+ /**
+ * 检查到用户开始说话停止,或者ASR_STOP 输入事件调用后,
+ */
+ @Override
+ public void onAsrEnd() {
+ for (IRecogListener listener : listeners) {
+ listener.onAsrEnd();
+ }
+ }
+
+ /**
+ * onAsrBegin 后 随着用户的说话,返回的临时结果
+ *
+ * @param results 可能返回多个结果,请取第一个结果
+ * @param recogResult 完整的结果
+ */
+ @Override
+ public void onAsrPartialResult(String[] results, RecogResult recogResult) {
+ for (IRecogListener listener : listeners) {
+ listener.onAsrPartialResult(results, recogResult);
+ }
+ }
+
+ /**
+ * 最终的识别结果
+ *
+ * @param results 可能返回多个结果,请取第一个结果
+ * @param recogResult 完整的结果
+ */
+ @Override
+ public void onAsrFinalResult(String[] results, RecogResult recogResult) {
+ for (IRecogListener listener : listeners) {
+ listener.onAsrFinalResult(results, recogResult);
+ }
+ }
+
+ @Override
+ public void onAsrFinish(RecogResult recogResult) {
+ for (IRecogListener listener : listeners) {
+ listener.onAsrFinish(recogResult);
+ }
+ }
+
+ @Override
+ public void onAsrFinishError(int errorCode, int subErrorCode, String descMessage,
+ RecogResult recogResult) {
+ for (IRecogListener listener : listeners) {
+ listener.onAsrFinishError(errorCode, subErrorCode, descMessage, recogResult);
+ }
+ }
+
+ /**
+ * 长语音识别结束
+ */
+ @Override
+ public void onAsrLongFinish() {
+ for (IRecogListener listener : listeners) {
+ listener.onAsrLongFinish();
+ }
+ }
+
+ @Override
+ public void onAsrVolume(int volumePercent, int volume) {
+ for (IRecogListener listener : listeners) {
+ listener.onAsrVolume(volumePercent, volume);
+ }
+ }
+
+ @Override
+ public void onAsrAudio(byte[] data, int offset, int length) {
+ for (IRecogListener listener : listeners) {
+ listener.onAsrAudio(data, offset, length);
+ }
+ }
+
+ @Override
+ public void onAsrExit() {
+ for (IRecogListener listener : listeners) {
+ listener.onAsrExit();
+ }
+ }
+
+ @Override
+ public void onAsrOnlineNluResult(String nluResult) {
+ for (IRecogListener listener : listeners) {
+ listener.onAsrOnlineNluResult(nluResult);
+ }
+ }
+
+ @Override
+ public void onOfflineLoaded() {
+ for (IRecogListener listener : listeners) {
+ listener.onOfflineLoaded();
+ }
+ }
+
+ @Override
+ public void onOfflineUnLoaded() {
+ for (IRecogListener listener : listeners) {
+ listener.onOfflineUnLoaded();
+ }
+ }
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/listener/IRecogListener.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/listener/IRecogListener.java
new file mode 100644
index 0000000..5f10996
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/listener/IRecogListener.java
@@ -0,0 +1,113 @@
+package com.baidu.aip.asrwakeup3.core.recog.listener;
+
+import com.baidu.aip.asrwakeup3.core.recog.RecogResult;
+
+/**
+ * 与SDK中回调参数的对应关系定义在RecogEventAdapter类中
+ */
+
+public interface IRecogListener {
+
+ /**
+ * CALLBACK_EVENT_ASR_READY
+ * ASR_START 输入事件调用后,引擎准备完毕
+ */
+ void onAsrReady();
+
+ /**
+ * CALLBACK_EVENT_ASR_BEGIN
+ * onAsrReady后检查到用户开始说话
+ */
+ void onAsrBegin();
+
+ /**
+ * CALLBACK_EVENT_ASR_END
+ * 检查到用户开始说话停止,或者ASR_STOP 输入事件调用后,
+ */
+ void onAsrEnd();
+
+ /**
+ * CALLBACK_EVENT_ASR_PARTIAL resultType=partial_result
+ * onAsrBegin 后 随着用户的说话,返回的临时结果
+ *
+ * @param results 可能返回多个结果,请取第一个结果
+ * @param recogResult 完整的结果
+ */
+ void onAsrPartialResult(String[] results, RecogResult recogResult);
+
+ /**
+ * 语音的在线语义结果
+ *
+ * CALLBACK_EVENT_ASR_PARTIAL resultType=nlu_result
+ * @param nluResult
+ */
+ void onAsrOnlineNluResult(String nluResult);
+
+ /**
+ * 不开启长语音仅回调一次,长语音的每一句话都会回调一次
+ * CALLBACK_EVENT_ASR_PARTIAL resultType=final_result
+ * 最终的识别结果
+ *
+ * @param results 可能返回多个结果,请取第一个结果
+ * @param recogResult 完整的结果
+ */
+ void onAsrFinalResult(String[] results, RecogResult recogResult);
+
+ /**
+ * CALLBACK_EVENT_ASR_FINISH
+ * @param recogResult 结束识别
+ */
+ void onAsrFinish(RecogResult recogResult);
+
+ /**
+ * CALLBACK_EVENT_ASR_FINISH error!=0
+ *
+ * @param errorCode
+ * @param subErrorCode
+ * @param descMessage
+ * @param recogResult
+ */
+ void onAsrFinishError(int errorCode, int subErrorCode, String descMessage,
+ RecogResult recogResult);
+
+ /**
+ * 长语音识别结束
+ */
+ void onAsrLongFinish();
+
+ /**
+ * CALLBACK_EVENT_ASR_VOLUME
+ * 音量回调
+ *
+ * @param volumePercent 音量的相对值,百分比,0-100
+ * @param volume 音量绝对值
+ */
+ void onAsrVolume(int volumePercent, int volume);
+
+ /**
+ * CALLBACK_EVENT_ASR_AUDIO
+ * @param data pcm格式,16bits 16000采样率
+ *
+ * @param offset
+ * @param length
+ */
+ void onAsrAudio(byte[] data, int offset, int length);
+
+ /**
+ * CALLBACK_EVENT_ASR_EXIT
+ * 引擎完成整个识别,空闲中
+ */
+ void onAsrExit();
+
+ /**
+ * CALLBACK_EVENT_ASR_LOADED
+ * 离线命令词资源加载成功
+ */
+ void onOfflineLoaded();
+
+ /**
+ * CALLBACK_EVENT_ASR_UNLOADED
+ * 离线命令词资源释放成功
+ */
+ void onOfflineUnLoaded();
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/listener/MessageStatusRecogListener.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/listener/MessageStatusRecogListener.java
new file mode 100644
index 0000000..1c75527
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/listener/MessageStatusRecogListener.java
@@ -0,0 +1,165 @@
+package com.baidu.aip.asrwakeup3.core.recog.listener;
+
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import com.baidu.aip.asrwakeup3.core.recog.RecogResult;
+import com.baidu.speech.asr.SpeechConstant;
+
+/**
+ * Created by fujiayi on 2017/6/16.
+ */
+
+public class MessageStatusRecogListener extends StatusRecogListener {
+ private Handler handler;
+
+ private long speechEndTime = 0;
+
+ private boolean needTime = true;
+
+ private static final String TAG = "MesStatusRecogListener";
+
+ public MessageStatusRecogListener(Handler handler) {
+ this.handler = handler;
+ }
+
+
+ @Override
+ public void onAsrReady() {
+ super.onAsrReady();
+ speechEndTime = 0;
+ sendStatusMessage(SpeechConstant.CALLBACK_EVENT_WAKEUP_READY, "引擎就绪,可以开始说话。");
+ }
+
+ @Override
+ public void onAsrBegin() {
+ super.onAsrBegin();
+ sendStatusMessage(SpeechConstant.CALLBACK_EVENT_ASR_BEGIN, "检测到用户说话");
+ }
+
+ @Override
+ public void onAsrEnd() {
+ super.onAsrEnd();
+ speechEndTime = System.currentTimeMillis();
+ sendMessage("【asr.end事件】检测到用户说话结束");
+ }
+
+ @Override
+ public void onAsrPartialResult(String[] results, RecogResult recogResult) {
+ sendStatusMessage(SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL,
+ "临时识别结果,结果是“" + results[0] + "”;原始json:" + recogResult.getOrigalJson());
+ super.onAsrPartialResult(results, recogResult);
+ }
+
+ @Override
+ public void onAsrFinalResult(String[] results, RecogResult recogResult) {
+ super.onAsrFinalResult(results, recogResult);
+ String message = "识别结束,结果是”" + results[0] + "”";
+ sendStatusMessage(SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL,
+ message + ";原始json:" + recogResult.getOrigalJson());
+ if (speechEndTime > 0) {
+ long currentTime = System.currentTimeMillis();
+ long diffTime = currentTime - speechEndTime;
+ message += ";说话结束到识别结束耗时【" + diffTime + "ms】" + currentTime;
+
+ }
+ speechEndTime = 0;
+ sendMessage(message, status, true);
+ }
+
+ @Override
+ public void onAsrFinishError(int errorCode, int subErrorCode, String descMessage,
+ RecogResult recogResult) {
+ super.onAsrFinishError(errorCode, subErrorCode, descMessage, recogResult);
+ String message = "【asr.finish事件】识别错误, 错误码:" + errorCode + " ," + subErrorCode + " ; " + descMessage;
+ sendStatusMessage(SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL, message);
+ if (speechEndTime > 0) {
+ long diffTime = System.currentTimeMillis() - speechEndTime;
+ message += "。说话结束到识别结束耗时【" + diffTime + "ms】";
+ }
+ speechEndTime = 0;
+ sendMessage(message, status, true);
+ speechEndTime = 0;
+ }
+
+ @Override
+ public void onAsrOnlineNluResult(String nluResult) {
+ super.onAsrOnlineNluResult(nluResult);
+ if (!nluResult.isEmpty()) {
+ sendStatusMessage(SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL, "原始语义识别结果json:" + nluResult);
+ }
+ }
+
+ @Override
+ public void onAsrFinish(RecogResult recogResult) {
+ super.onAsrFinish(recogResult);
+ sendStatusMessage(SpeechConstant.CALLBACK_EVENT_ASR_FINISH, "识别一段话结束。如果是长语音的情况会继续识别下段话。");
+
+ }
+
+ /**
+ * 长语音识别结束
+ */
+ @Override
+ public void onAsrLongFinish() {
+ super.onAsrLongFinish();
+ sendStatusMessage(SpeechConstant.CALLBACK_EVENT_ASR_LONG_SPEECH, "长语音识别结束。");
+ }
+
+
+ /**
+ * 使用离线命令词时,有该回调说明离线语法资源加载成功
+ */
+ @Override
+ public void onOfflineLoaded() {
+ sendStatusMessage(SpeechConstant.CALLBACK_EVENT_ASR_LOADED, "离线资源加载成功。没有此回调可能离线语法功能不能使用。");
+ }
+
+ /**
+ * 使用离线命令词时,有该回调说明离线语法资源加载成功
+ */
+ @Override
+ public void onOfflineUnLoaded() {
+ sendStatusMessage(SpeechConstant.CALLBACK_EVENT_ASR_UNLOADED, "离线资源卸载成功。");
+ }
+
+ @Override
+ public void onAsrExit() {
+ super.onAsrExit();
+ sendStatusMessage(SpeechConstant.CALLBACK_EVENT_ASR_EXIT, "识别引擎结束并空闲中");
+ }
+
+ private void sendStatusMessage(String eventName, String message) {
+ message = "[" + eventName + "]" + message;
+ sendMessage(message, status);
+ }
+
+ private void sendMessage(String message) {
+ sendMessage(message, WHAT_MESSAGE_STATUS);
+ }
+
+ private void sendMessage(String message, int what) {
+ sendMessage(message, what, false);
+ }
+
+
+ private void sendMessage(String message, int what, boolean highlight) {
+
+
+ if (needTime && what != STATUS_FINISHED) {
+ message += " ;time=" + System.currentTimeMillis();
+ }
+ if (handler == null) {
+ Log.i(TAG, message);
+ return;
+ }
+ Message msg = Message.obtain();
+ msg.what = what;
+ msg.arg1 = status;
+ if (highlight) {
+ msg.arg2 = 1;
+ }
+ msg.obj = message + "\n";
+ handler.sendMessage(msg);
+ }
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/listener/RecogEventAdapter.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/listener/RecogEventAdapter.java
new file mode 100644
index 0000000..994fa2b
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/listener/RecogEventAdapter.java
@@ -0,0 +1,112 @@
+package com.baidu.aip.asrwakeup3.core.recog.listener;
+
+import android.util.Log;
+import com.baidu.aip.asrwakeup3.core.util.MyLogger;
+import com.baidu.speech.EventListener;
+import com.baidu.speech.asr.SpeechConstant;
+import org.json.JSONException;
+import org.json.JSONObject;
+import com.baidu.aip.asrwakeup3.core.recog.RecogResult;
+
+/**
+ * Created by fujiayi on 2017/6/14.
+ */
+
+public class RecogEventAdapter implements EventListener {
+
+ private IRecogListener listener;
+
+ private static final String TAG = "RecogEventAdapter";
+
+ public RecogEventAdapter(IRecogListener listener) {
+ this.listener = listener;
+ }
+
+ // 基于DEMO集成3.1 开始回调事件
+ @Override
+ public void onEvent(String name, String params, byte[] data, int offset, int length) {
+ String currentJson = params;
+ String logMessage = "name:" + name + "; params:" + params;
+
+ // logcat 中 搜索RecogEventAdapter,即可以看见下面一行的日志
+ Log.i(TAG, logMessage);
+ if (false) { // 可以调试,不需要后续逻辑
+ return;
+ }
+ if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_LOADED)) {
+ listener.onOfflineLoaded();
+ } else if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_UNLOADED)) {
+ listener.onOfflineUnLoaded();
+ } else if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_READY)) {
+ // 引擎准备就绪,可以开始说话
+ listener.onAsrReady();
+ } else if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_BEGIN)) {
+ // 检测到用户的已经开始说话
+ listener.onAsrBegin();
+
+ } else if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_END)) {
+ // 检测到用户的已经停止说话
+ listener.onAsrEnd();
+
+ } else if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_PARTIAL)) {
+ RecogResult recogResult = RecogResult.parseJson(params);
+ // 识别结果
+ String[] results = recogResult.getResultsRecognition();
+ if (recogResult.isFinalResult()) {
+ // 最终识别结果,长语音每一句话会回调一次
+ listener.onAsrFinalResult(results, recogResult);
+ } else if (recogResult.isPartialResult()) {
+ // 临时识别结果
+ listener.onAsrPartialResult(results, recogResult);
+ } else if (recogResult.isNluResult()) {
+ // 语义理解结果
+ listener.onAsrOnlineNluResult(new String(data, offset, length));
+ }
+
+ } else if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_FINISH)) {
+ // 识别结束
+ RecogResult recogResult = RecogResult.parseJson(params);
+ if (recogResult.hasError()) {
+ int errorCode = recogResult.getError();
+ int subErrorCode = recogResult.getSubError();
+ MyLogger.error(TAG, "asr error:" + params);
+ listener.onAsrFinishError(errorCode, subErrorCode, recogResult.getDesc(), recogResult);
+ } else {
+ listener.onAsrFinish(recogResult);
+ }
+ } else if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_LONG_SPEECH)) { // 长语音
+ listener.onAsrLongFinish(); // 长语音
+ } else if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_EXIT)) {
+ listener.onAsrExit();
+ } else if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_VOLUME)) {
+ // Logger.info(TAG, "asr volume event:" + params);
+ Volume vol = parseVolumeJson(params);
+ listener.onAsrVolume(vol.volumePercent, vol.volume);
+ } else if (name.equals(SpeechConstant.CALLBACK_EVENT_ASR_AUDIO)) {
+ if (data.length != length) {
+ MyLogger.error(TAG, "internal error: asr.audio callback data length is not equal to length param");
+ }
+ listener.onAsrAudio(data, offset, length);
+ }
+ }
+
+ private Volume parseVolumeJson(String jsonStr) {
+ Volume vol = new Volume();
+ vol.origalJson = jsonStr;
+ try {
+ JSONObject json = new JSONObject(jsonStr);
+ vol.volumePercent = json.getInt("volume-percent");
+ vol.volume = json.getInt("volume");
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return vol;
+ }
+
+ private class Volume {
+ private int volumePercent = -1;
+ private int volume = -1;
+ private String origalJson;
+ }
+
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/listener/StatusRecogListener.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/listener/StatusRecogListener.java
new file mode 100644
index 0000000..b8c9513
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/recog/listener/StatusRecogListener.java
@@ -0,0 +1,110 @@
+package com.baidu.aip.asrwakeup3.core.recog.listener;
+
+/**
+ * Created by fujiayi on 2017/6/14.
+ */
+
+import android.util.Log;
+import com.baidu.aip.asrwakeup3.core.recog.IStatus;
+import com.baidu.aip.asrwakeup3.core.recog.RecogResult;
+
+/**
+ * 根据回调,判断asr引擎的状态
+ *
+ * 通常状态变化如下:
+ *
+ * STATUS_NONE 初始状态
+ * STATUS_READY 引擎准备完毕
+ * STATUS_SPEAKING 用户开始说话到用户说话完毕前
+ * STATUS_RECOGNITION 用户说话完毕后,识别结束前
+ * STATUS_FINISHED 获得最终识别结果
+ */
+public class StatusRecogListener implements IRecogListener, IStatus {
+
+ private static final String TAG = "StatusRecogListener";
+
+ /**
+ * 识别的引擎当前的状态
+ */
+ protected int status = STATUS_NONE;
+
+ @Override
+ public void onAsrReady() {
+ status = STATUS_READY;
+ }
+
+ @Override
+ public void onAsrBegin() {
+ status = STATUS_SPEAKING;
+ }
+
+ @Override
+ public void onAsrEnd() {
+ status = STATUS_RECOGNITION;
+ }
+
+ @Override
+ public void onAsrPartialResult(String[] results, RecogResult recogResult) {
+
+ }
+
+ @Override
+ public void onAsrFinalResult(String[] results, RecogResult recogResult) {
+ status = STATUS_FINISHED;
+ }
+
+ @Override
+ public void onAsrFinish(RecogResult recogResult) {
+ status = STATUS_FINISHED;
+ }
+
+
+ @Override
+ public void onAsrFinishError(int errorCode, int subErrorCode, String descMessage,
+ RecogResult recogResult) {
+ status = STATUS_FINISHED;
+ }
+
+ @Override
+ public void onAsrLongFinish() {
+ status = STATUS_LONG_SPEECH_FINISHED;
+ }
+
+ @Override
+ public void onAsrVolume(int volumePercent, int volume) {
+ Log.i(TAG, "音量百分比" + volumePercent + " ; 音量" + volume);
+ }
+
+ @Override
+ public void onAsrAudio(byte[] data, int offset, int length) {
+ if (offset != 0 || data.length != length) {
+ byte[] actualData = new byte[length];
+ System.arraycopy(data, 0, actualData, 0, length);
+ data = actualData;
+ }
+
+ Log.i(TAG, "音频数据回调, length:" + data.length);
+ }
+
+ @Override
+ public void onAsrExit() {
+ status = STATUS_NONE;
+ }
+
+ @Override
+ public void onAsrOnlineNluResult(String nluResult) {
+ status = STATUS_FINISHED;
+ }
+
+ @Override
+ public void onOfflineLoaded() {
+
+ }
+
+ @Override
+ public void onOfflineUnLoaded() {
+
+ }
+
+
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/AuthUtil.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/AuthUtil.java
new file mode 100644
index 0000000..d5e92e8
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/AuthUtil.java
@@ -0,0 +1,35 @@
+package com.baidu.aip.asrwakeup3.core.util;
+
+import com.baidu.speech.asr.SpeechConstant;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * 为方便说明 apiKey 简称ak,secretKey简称 sk
+ * ak sk为敏感信息,泄露后别人可使用ak sk 消耗你的调用次数,造成财产损失,请妥善保存
+ * 建议你将ak sk保存在自己服务端,通过接口请求获得。
+ * 如果暂时没有后端服务接口,建议将ak sk加密存储减少暴露风险。
+ **/
+public class AuthUtil {
+ public static String getAk(){
+ //todo 填入apiKey
+ return "请填入您的apiKey";
+ }
+ public static String getSk(){
+ //todo 填入secretKey
+ return "请填入您的secretKey";
+ }
+ public static String getAppId(){
+ //todo 填入appId
+ return "请填入您的appId";
+ }
+
+ public static Map getParam(){
+ Map params = new LinkedHashMap();
+ params.put(SpeechConstant.APP_ID, getAppId()); // 添加appId
+ params.put(SpeechConstant.APP_KEY, getAk()); // 添加apiKey
+ params.put(SpeechConstant.SECRET, getSk()); // 添加secretKey
+ return params;
+ }
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/FileUtil.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/FileUtil.java
new file mode 100644
index 0000000..7daf716
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/FileUtil.java
@@ -0,0 +1,73 @@
+package com.baidu.aip.asrwakeup3.core.util;
+
+import android.content.res.AssetManager;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Created by fujiayi on 2017/5/19.
+ */
+
+public class FileUtil {
+
+ public static boolean makeDir(String dirPath) {
+ File file = new File(dirPath);
+ if (!file.exists()) {
+ return file.mkdirs();
+ } else {
+ return true;
+ }
+ }
+
+ public static String getContentFromAssetsFile(AssetManager assets, String source) {
+ InputStream is = null;
+ FileOutputStream fos = null;
+ String result = "";
+ try {
+ is = assets.open(source);
+ int lenght = is.available();
+ byte[] buffer = new byte[lenght];
+ is.read(buffer);
+ result = new String(buffer, "utf8");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
+ public static boolean copyFromAssets(AssetManager assets, String source, String dest,
+ boolean isCover) throws IOException {
+ File file = new File(dest);
+ boolean isCopyed = false;
+ if (isCover || (!isCover && !file.exists())) {
+ InputStream is = null;
+ FileOutputStream fos = null;
+ try {
+ is = assets.open(source);
+ String path = dest;
+ fos = new FileOutputStream(path);
+ byte[] buffer = new byte[1024];
+ int size = 0;
+ while ((size = is.read(buffer, 0, 1024)) >= 0) {
+ fos.write(buffer, 0, size);
+ }
+ isCopyed = true;
+ } finally {
+ if (fos != null) {
+ try {
+ fos.close();
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ }
+ }
+ }
+
+ }
+ return isCopyed;
+ }
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/MyLogger.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/MyLogger.java
new file mode 100644
index 0000000..5b9cc7a
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/MyLogger.java
@@ -0,0 +1,59 @@
+package com.baidu.aip.asrwakeup3.core.util;
+
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+
+
+/**
+ * 记录日志的时候, 顺带往handler记录一份
+ */
+
+public class MyLogger {
+ private static final String TAG = "MyLogger";
+
+ private static final String INFO = "INFO";
+
+ private static final String ERROR = "ERROR";
+
+ private static final boolean ENABLE = true;
+
+ private static Handler handler;
+
+ public static void info(String message) {
+ info(TAG, message);
+ }
+
+ public static void info(String tag, String message) {
+ log(INFO, tag, message);
+ }
+
+ public static void error(String message) {
+ error(TAG, message);
+ }
+
+ public static void error(String tag, String message) {
+ log(ERROR, tag, message);
+ }
+
+ public static void setHandler(Handler handler) {
+ MyLogger.handler = handler;
+ }
+
+ private static void log(String level, String tag, String message) {
+ if (!ENABLE) {
+ return;
+ }
+ if (level.equals(INFO)) {
+ Log.i(tag, message);
+
+ } else if (level.equals(ERROR)) {
+ Log.e(tag, message);
+ }
+ if (handler != null) {
+ Message msg = Message.obtain();
+ msg.obj = "[" + level + "]" + message + "\n";
+ handler.sendMessage(msg);
+ }
+ }
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/bluetooth/AndroidAudioManager.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/bluetooth/AndroidAudioManager.java
new file mode 100644
index 0000000..bf3f3d5
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/bluetooth/AndroidAudioManager.java
@@ -0,0 +1,293 @@
+package com.baidu.aip.asrwakeup3.core.util.bluetooth;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothHeadset;
+import android.bluetooth.BluetoothProfile;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.media.AudioManager;
+import android.util.Log;
+
+import java.util.List;
+
+import static android.media.AudioManager.STREAM_VOICE_CALL;
+
+public class AndroidAudioManager {
+
+ private static volatile AndroidAudioManager instance;
+
+ private BluetoothAdapter mBluetoothAdapter;
+
+ private AudioManager mAudioManager;
+
+ private boolean mIsBluetoothHeadsetConnected;
+
+ private boolean mIsBluetoothHeadsetScoConnected;
+
+ private BluetoothReceiver mBluetoothReceiver;
+
+ private HeadsetReceiver mHeadsetReceiver;
+
+ private boolean mAudioFocused;
+
+ private Context mContext;
+ private BluetoothHeadset mBluetoothHeadset;
+
+ private AndroidAudioManager(Context context) {
+ mAudioManager = ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE));
+ this.mContext = context.getApplicationContext();
+ }
+
+ public AudioManager getAudioManager() {
+ return mAudioManager;
+ }
+
+ public static AndroidAudioManager getInstance(Context context) {
+ if (instance == null) {
+ synchronized (AndroidAudioManager.class) {
+ if (instance == null) {
+ instance = new AndroidAudioManager(context);
+ }
+ }
+ }
+ return instance;
+ }
+
+ public void startBluetooth() {
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ if (mBluetoothAdapter != null) {
+ Log.i("AndroidAudioManager", "[Audio Manager] [Bluetooth] Adapter found");
+ if (mAudioManager.isBluetoothScoAvailableOffCall()) {
+ Log.i("AndroidAudioManager", "[Audio Manager] [Bluetooth] SCO available off call, continue");
+ } else {
+ Log.w("AndroidAudioManager", "[Audio Manager] [Bluetooth] SCO not available off call !");
+ }
+ if (mBluetoothAdapter.isEnabled()) {
+ Log.i("AndroidAudioManager", "[Audio Manager] [Bluetooth] Adapter enabled");
+ mBluetoothReceiver = new BluetoothReceiver();
+ mIsBluetoothHeadsetConnected = false;
+ mIsBluetoothHeadsetScoConnected = false;
+
+ BluetoothProfile.ServiceListener bluetoothServiceListener =
+ new BluetoothProfile.ServiceListener() {
+ public void onServiceConnected(int profile, BluetoothProfile proxy) {
+ if (profile == BluetoothProfile.HEADSET) {
+ Log.i("AndroidAudioManager",
+ "[Audio Manager] [Bluetooth] HEADSET profile connected");
+ mBluetoothHeadset = (BluetoothHeadset) proxy;
+
+ List devices =
+ mBluetoothHeadset.getConnectedDevices();
+ if (devices.size() > 0) {
+ Log.i("AndroidAudioManager",
+ "[Audio Manager] [Bluetooth] A device is already connected");
+ bluetoothHeadetConnectionChanged(true);
+ }
+
+ Log.i("AndroidAudioManager",
+ "[Audio Manager] [Bluetooth] Registering bluetooth receiver");
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
+ filter.addAction(
+ BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
+ filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
+ filter.addAction(
+ BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT);
+
+ Intent sticky =
+ mContext.registerReceiver(mBluetoothReceiver, filter);
+ int state =
+ sticky.getIntExtra(
+ AudioManager.EXTRA_SCO_AUDIO_STATE,
+ AudioManager.SCO_AUDIO_STATE_DISCONNECTED);
+ if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
+ Log.i("AndroidAudioManager",
+ "[Audio Manager] [Bluetooth] Bluetooth headset SCO connected");
+ bluetoothHeadetScoConnectionChanged(true);
+ } else if (state == AudioManager.SCO_AUDIO_STATE_DISCONNECTED) {
+ Log.i("AndroidAudioManager",
+ "[Audio Manager] [Bluetooth] Bluetooth headset SCO disconnected");
+ bluetoothHeadetScoConnectionChanged(false);
+ } else if (state == AudioManager.SCO_AUDIO_STATE_CONNECTING) {
+ Log.i("AndroidAudioManager",
+ "[Audio Manager] [Bluetooth] Bluetooth headset SCO connecting");
+ } else if (state == AudioManager.SCO_AUDIO_STATE_ERROR) {
+ Log.i("AndroidAudioManager",
+ "[Audio Manager] [Bluetooth] Bluetooth headset SCO connection error");
+ } else {
+ Log.w("AndroidAudioManager",
+ "[Audio Manager] [Bluetooth] Bluetooth headset " +
+ "unknown SCO state changed: "
+ + state);
+ }
+ }
+ }
+
+ public void onServiceDisconnected(int profile) {
+ if (profile == BluetoothProfile.HEADSET) {
+ Log.i("AndroidAudioManager",
+ "[Audio Manager] [Bluetooth] HEADSET profile disconnected");
+ mBluetoothHeadset = null;
+ mIsBluetoothHeadsetConnected = false;
+ mIsBluetoothHeadsetScoConnected = false;
+ }
+ }
+ };
+ mBluetoothAdapter.getProfileProxy(
+ mContext, bluetoothServiceListener, BluetoothProfile.HEADSET);
+ }
+ }
+ }
+
+
+ // Bluetooth
+
+ public synchronized void bluetoothHeadetConnectionChanged(boolean connected) {
+ mIsBluetoothHeadsetConnected = connected;
+ mAudioManager.setBluetoothScoOn(connected);
+ mAudioManager.startBluetoothSco();
+ routeAudioToBluetooth();
+ }
+
+
+ public synchronized boolean isBluetoothHeadsetConnected() {
+ return mIsBluetoothHeadsetConnected;
+ }
+
+ public synchronized void bluetoothHeadetScoConnectionChanged(boolean connected) {
+ mIsBluetoothHeadsetScoConnected = connected;
+ }
+
+ public synchronized boolean isUsingBluetoothAudioRoute() {
+ return mIsBluetoothHeadsetScoConnected;
+ }
+
+ public synchronized void routeAudioToBluetooth() {
+ if (!isBluetoothHeadsetConnected()) {
+ Log.w("AndroidAudioManager", "[Audio Manager] [Bluetooth] No headset connected");
+ return;
+ }
+ if (mAudioManager.getMode() != AudioManager.MODE_IN_COMMUNICATION) {
+ Log.w("AndroidAudioManager",
+ "[Audio Manager] [Bluetooth] Changing audio mode to MODE_IN_COMMUNICATION " +
+ "and requesting STREAM_VOICE_CALL focus");
+ mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
+ requestAudioFocus(STREAM_VOICE_CALL);
+ }
+ changeBluetoothSco(true);
+ }
+
+ private void requestAudioFocus(int stream) {
+ if (!mAudioFocused) {
+ int res =
+ mAudioManager.requestAudioFocus(
+ null, stream, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE);
+ Log.d("AndroidAudioManager",
+ "[Audio Manager] Audio focus requested: "
+ + (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED
+ ? "Granted"
+ : "Denied"));
+ if (res == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
+ mAudioFocused = true;
+ }
+ }
+ }
+
+ private synchronized void changeBluetoothSco(final boolean enable) {
+ // IT WILL TAKE A CERTAIN NUMBER OF CALLS TO EITHER START/STOP BLUETOOTH SCO FOR IT TO WORK
+ if (enable && mIsBluetoothHeadsetScoConnected) {
+ Log.i("AndroidAudioManager", "[Audio Manager] [Bluetooth] SCO already enabled, skipping");
+ return;
+ } else if (!enable && !mIsBluetoothHeadsetScoConnected) {
+ Log.i("AndroidAudioManager", "[Audio Manager] [Bluetooth] SCO already disabled, skipping");
+ return;
+ }
+
+ new Thread() {
+ @Override
+ public void run() {
+ boolean resultAcknoledged;
+ int retries = 0;
+ do {
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException e) {
+ Log.e("AndroidAudioManager", e.getMessage(), e);
+ }
+
+ synchronized (AndroidAudioManager.this) {
+ if (enable) {
+ Log.i("AndroidAudioManager",
+ "[Audio Manager] [Bluetooth] Starting SCO: try number "
+ + retries);
+ mAudioManager.startBluetoothSco();
+ } else {
+ Log.i("AndroidAudioManager",
+ "[Audio Manager] [Bluetooth] Stopping SCO: try number "
+ + retries);
+ mAudioManager.stopBluetoothSco();
+ }
+ resultAcknoledged = isUsingBluetoothAudioRoute() == enable;
+ retries++;
+ }
+ } while (!resultAcknoledged && retries < 10);
+ }
+ }.start();
+ }
+
+ public void destroy() {
+ if (mBluetoothAdapter != null && mBluetoothHeadset != null) {
+ Log.i("AndroidAudioManager", "[Audio Manager] [Bluetooth] Closing HEADSET profile proxy");
+ mBluetoothAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
+ }
+
+ Log.i("AndroidAudioManager", "[Audio Manager] [Bluetooth] Unegistering bluetooth receiver");
+ if (mBluetoothReceiver != null) {
+ mContext.unregisterReceiver(mBluetoothReceiver);
+ }
+ synchronized (AndroidAudioManager.class) {
+ mContext = null;
+ instance = null;
+ }
+ }
+
+
+ public void startSimpleBluetooth() {
+ mAudioManager.setBluetoothScoOn(true);
+ mAudioManager.startBluetoothSco();
+ }
+
+ public void destorySimpleBluetooth() {
+ mAudioManager.setBluetoothScoOn(false);
+ mAudioManager.stopBluetoothSco();
+ }
+
+ // HEADSET 插耳机的
+
+ public void enableHeadsetReceiver() {
+ mHeadsetReceiver = new HeadsetReceiver();
+
+ Log.i("AndroidAudioManager", "[Audio Manager] Registering headset receiver");
+ mContext.registerReceiver(
+ mHeadsetReceiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
+ mContext.registerReceiver(
+ mHeadsetReceiver, new IntentFilter(AudioManager.ACTION_HEADSET_PLUG));
+ }
+
+ public void routeAudioToEarPiece() {
+ routeAudioToSpeakerHelper(false);
+ }
+
+ public void routeAudioToSpeakerHelper(boolean speakerOn) {
+ Log.w("AndroidAudioManager", "[Audio Manager] Routing audio to " + (speakerOn ? "speaker" : "earpiece"));
+ if (mIsBluetoothHeadsetScoConnected) {
+ Log.w("AndroidAudioManager", "[Audio Manager] [Bluetooth] Disabling bluetooth audio route");
+ changeBluetoothSco(false);
+ }
+
+ mAudioManager.setSpeakerphoneOn(speakerOn);
+ }
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/bluetooth/BluetoothReceiver.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/bluetooth/BluetoothReceiver.java
new file mode 100644
index 0000000..7007583
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/bluetooth/BluetoothReceiver.java
@@ -0,0 +1,92 @@
+package com.baidu.aip.asrwakeup3.core.util.bluetooth;
+
+import android.bluetooth.BluetoothHeadset;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.media.AudioManager;
+import android.util.Log;
+
+public class BluetoothReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (action.equals(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED)) {
+ int state =
+ intent.getIntExtra(
+ BluetoothHeadset.EXTRA_STATE, BluetoothHeadset.STATE_DISCONNECTED);
+ if (state == BluetoothHeadset.STATE_CONNECTED) {
+ Log.i("BluetoothReceiver", "[Bluetooth] Bluetooth headset connected");
+ AndroidAudioManager.getInstance(context).bluetoothHeadetConnectionChanged(true);
+ } else if (state == BluetoothHeadset.STATE_DISCONNECTED) {
+ Log.i("BluetoothReceiver", "[Bluetooth] Bluetooth headset disconnected");
+ AndroidAudioManager.getInstance(context).bluetoothHeadetConnectionChanged(false);
+ } else {
+ Log.w("BluetoothReceiver", "[Bluetooth] Bluetooth headset unknown state changed: " + state);
+ }
+ } else if (action.equals(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED)) {
+ int state =
+ intent.getIntExtra(
+ BluetoothHeadset.EXTRA_STATE,
+ BluetoothHeadset.STATE_AUDIO_DISCONNECTED);
+ if (state == BluetoothHeadset.STATE_AUDIO_CONNECTED) {
+ Log.i("BluetoothReceiver", "[Bluetooth] Bluetooth headset audio connected");
+ // AndroidAudioManager.getInstance(context).bluetoothHeadetAudioConnectionChanged(true);
+ } else if (state == BluetoothHeadset.STATE_AUDIO_DISCONNECTED) {
+ Log.i("BluetoothReceiver", "[Bluetooth] Bluetooth headset audio disconnected");
+ // AndroidAudioManager.getInstance(context).bluetoothHeadetAudioConnectionChanged(false);
+ } else {
+ Log.w("BluetoothReceiver", "[Bluetooth] Bluetooth headset unknown audio state changed: " + state);
+ }
+ } else if (action.equals(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)) {
+ int state =
+ intent.getIntExtra(
+ AudioManager.EXTRA_SCO_AUDIO_STATE,
+ AudioManager.SCO_AUDIO_STATE_DISCONNECTED);
+ if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
+ Log.i("BluetoothReceiver", "[Bluetooth] Bluetooth headset SCO connected");
+ AndroidAudioManager.getInstance(context).bluetoothHeadetScoConnectionChanged(true);
+ } else if (state == AudioManager.SCO_AUDIO_STATE_DISCONNECTED) {
+ Log.i("BluetoothReceiver", "[Bluetooth] Bluetooth headset SCO disconnected");
+ AndroidAudioManager.getInstance(context).bluetoothHeadetScoConnectionChanged(false);
+ } else if (state == AudioManager.SCO_AUDIO_STATE_CONNECTING) {
+ Log.i("BluetoothReceiver", "[Bluetooth] Bluetooth headset SCO connecting");
+ } else if (state == AudioManager.SCO_AUDIO_STATE_ERROR) {
+ Log.i("BluetoothReceiver", "[Bluetooth] Bluetooth headset SCO connection error");
+ } else {
+ Log.w("BluetoothReceiver", "[Bluetooth] Bluetooth headset unknown SCO state changed: " + state);
+ }
+ } else if (action.equals(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT)) {
+ String command =
+ intent.getStringExtra(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD);
+ int type =
+ intent.getIntExtra(
+ BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE, -1);
+
+ String commandType;
+ switch (type) {
+ case BluetoothHeadset.AT_CMD_TYPE_ACTION:
+ commandType = "AT Action";
+ break;
+ case BluetoothHeadset.AT_CMD_TYPE_READ:
+ commandType = "AT Read";
+ break;
+ case BluetoothHeadset.AT_CMD_TYPE_TEST:
+ commandType = "AT Test";
+ break;
+ case BluetoothHeadset.AT_CMD_TYPE_SET:
+ commandType = "AT Set";
+ break;
+ case BluetoothHeadset.AT_CMD_TYPE_BASIC:
+ commandType = "AT Basic";
+ break;
+ default:
+ commandType = "AT Unknown";
+ break;
+ }
+ Log.i("BluetoothReceiver", "[Bluetooth] Vendor action " + commandType + " : " + command);
+ } else {
+ Log.w("BluetoothReceiver", "[Bluetooth] Bluetooth unknown action: " + action);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/bluetooth/HeadsetReceiver.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/bluetooth/HeadsetReceiver.java
new file mode 100644
index 0000000..35a8062
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/util/bluetooth/HeadsetReceiver.java
@@ -0,0 +1,41 @@
+package com.baidu.aip.asrwakeup3.core.util.bluetooth;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.media.AudioManager;
+import android.util.Log;
+
+public class HeadsetReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (action.equals(AudioManager.ACTION_HEADSET_PLUG)) {
+ // This happens when the user plugs a Jack headset to the device for example
+ int state = intent.getIntExtra("state", 0);
+ String name = intent.getStringExtra("name");
+ int hasMicrophone = intent.getIntExtra("microphone", 0);
+
+ if (state == 0) {
+ Log.i("HeadsetReceiver", "[Headset] Headset disconnected:" + name);
+ } else if (state == 1) {
+ Log.i("HeadsetReceiver", "[Headset] Headset connected:" + name);
+ if (hasMicrophone == 1) {
+ Log.i("HeadsetReceiver", "[Headset] Headset " + name + " has a microphone");
+ }
+ } else {
+ Log.w("HeadsetReceiver", "[Headset] Unknown headset plugged state: " + state);
+ }
+
+ AndroidAudioManager.getInstance(context).routeAudioToEarPiece();
+ // LinphoneManager.getCallManager().refreshInCallActions();
+ } else if (action.equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
+ // This happens when the user disconnect a headset, so we shouldn't play audio loudly
+ Log.i("HeadsetReceiver", "[Headset] Noisy state detected, most probably a headset has been disconnected");
+ AndroidAudioManager.getInstance(context).routeAudioToEarPiece();
+ // LinphoneManager.getCallManager().refreshInCallActions();
+ } else {
+ Log.w("HeadsetReceiver", "[Headset] Unknown action: " + action);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/MyWakeup.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/MyWakeup.java
new file mode 100644
index 0000000..1a0b1de
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/MyWakeup.java
@@ -0,0 +1,68 @@
+package com.baidu.aip.asrwakeup3.core.wakeup;
+
+import android.content.Context;
+import com.baidu.aip.asrwakeup3.core.util.MyLogger;
+import com.baidu.aip.asrwakeup3.core.wakeup.listener.IWakeupListener;
+import com.baidu.speech.EventListener;
+import com.baidu.speech.EventManager;
+import com.baidu.speech.EventManagerFactory;
+import com.baidu.speech.asr.SpeechConstant;
+import org.json.JSONObject;
+
+import java.util.Map;
+
+/**
+ * Created by fujiayi on 2017/6/20.
+ */
+
+public class MyWakeup {
+
+
+ private static boolean isInited = false;
+
+ private EventManager wp;
+ private EventListener eventListener;
+
+ private static final String TAG = "MyWakeup";
+
+ public MyWakeup(Context context, EventListener eventListener) {
+ if (isInited) {
+ MyLogger.error(TAG, "还未调用release(),请勿新建一个新类");
+ throw new RuntimeException("还未调用release(),请勿新建一个新类");
+ }
+ isInited = true;
+ this.eventListener = eventListener;
+ wp = EventManagerFactory.create(context, "wp");
+ wp.registerListener(eventListener);
+ }
+
+ public MyWakeup(Context context, IWakeupListener eventListener) {
+ this(context, new WakeupEventAdapter(eventListener));
+ }
+
+ public void start(Map params) {
+ String json = new JSONObject(params).toString();
+ MyLogger.info(TAG + ".Debug", "wakeup params(反馈请带上此行日志):" + json);
+ wp.send(SpeechConstant.WAKEUP_START, json, null, 0, 0);
+ }
+
+ public void stop() {
+ MyLogger.info(TAG, "唤醒结束");
+ wp.send(SpeechConstant.WAKEUP_STOP, null, null, 0, 0);
+ }
+
+ public void setEventListener(EventListener eventListener) {
+ this.eventListener = eventListener;
+ }
+
+ public void setEventListener(IWakeupListener eventListener) {
+ this.eventListener = new WakeupEventAdapter(eventListener);
+ }
+
+ public void release() {
+ stop();
+ wp.unregisterListener(eventListener);
+ wp = null;
+ isInited = false;
+ }
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/WakeUpResult.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/WakeUpResult.java
new file mode 100644
index 0000000..1cc6762
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/WakeUpResult.java
@@ -0,0 +1,91 @@
+package com.baidu.aip.asrwakeup3.core.wakeup;
+
+import com.baidu.aip.asrwakeup3.core.util.MyLogger;
+import com.baidu.speech.asr.SpeechConstant;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Created by fujiayi on 2017/6/24.
+ */
+public class WakeUpResult {
+ private String name;
+ private String origalJson;
+ private String word;
+ private String desc;
+ private int errorCode;
+
+ private static int ERROR_NONE = 0;
+
+ private static final String TAG = "WakeUpResult";
+
+ public boolean hasError() {
+ return errorCode != ERROR_NONE;
+ }
+
+ public String getOrigalJson() {
+ return origalJson;
+ }
+
+ public void setOrigalJson(String origalJson) {
+ this.origalJson = origalJson;
+ }
+
+ public String getWord() {
+ return word;
+ }
+
+ public void setWord(String word) {
+ this.word = word;
+ }
+
+ public String getDesc() {
+ return desc;
+ }
+
+ public void setDesc(String desc) {
+ this.desc = desc;
+ }
+
+ public int getErrorCode() {
+ return errorCode;
+ }
+
+ public void setErrorCode(int errorCode) {
+ this.errorCode = errorCode;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public static WakeUpResult parseJson(String name, String jsonStr) {
+ WakeUpResult result = new WakeUpResult();
+ result.setOrigalJson(jsonStr);
+ try {
+ JSONObject json = new JSONObject(jsonStr);
+ if (SpeechConstant.CALLBACK_EVENT_WAKEUP_SUCCESS.equals(name)) {
+ int error = json.optInt("errorCode");
+ result.setErrorCode(error);
+ result.setDesc(json.optString("errorDesc"));
+ if (!result.hasError()) {
+ result.setWord(json.optString("word"));
+ }
+ } else {
+ int error = json.optInt("error");
+ result.setErrorCode(error);
+ result.setDesc(json.optString("desc"));
+ }
+
+ } catch (JSONException e) {
+ MyLogger.error(TAG, "Json parse error" + jsonStr);
+ e.printStackTrace();
+ }
+
+ return result;
+ }
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/WakeupEventAdapter.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/WakeupEventAdapter.java
new file mode 100644
index 0000000..7a4b795
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/WakeupEventAdapter.java
@@ -0,0 +1,47 @@
+package com.baidu.aip.asrwakeup3.core.wakeup;
+
+import com.baidu.aip.asrwakeup3.core.util.MyLogger;
+import com.baidu.aip.asrwakeup3.core.wakeup.listener.IWakeupListener;
+import com.baidu.speech.EventListener;
+import com.baidu.speech.asr.SpeechConstant;
+
+/**
+ * Created by fujiayi on 2017/6/20.
+ */
+
+public class WakeupEventAdapter implements EventListener {
+ private IWakeupListener listener;
+
+ public WakeupEventAdapter(IWakeupListener listener) {
+ this.listener = listener;
+ }
+
+ private static final String TAG = "WakeupEventAdapter";
+ // 基于DEMO唤醒3.1 开始回调事件
+ @Override
+ public void onEvent(String name, String params, byte[] data, int offset, int length) {
+ // android studio日志Monitor 中搜索 WakeupEventAdapter即可看见下面一行的日志
+ MyLogger.info(TAG, "wakeup name:" + name + "; params:" + params);
+ if (SpeechConstant.CALLBACK_EVENT_WAKEUP_SUCCESS.equals(name)) { // 识别唤醒词成功
+ WakeUpResult result = WakeUpResult.parseJson(name, params);
+ int errorCode = result.getErrorCode();
+ if (result.hasError()) { // error不为0依旧有可能是异常情况
+ listener.onError(errorCode, "", result);
+ } else {
+ String word = result.getWord();
+ listener.onSuccess(word, result);
+
+ }
+ } else if (SpeechConstant.CALLBACK_EVENT_WAKEUP_ERROR.equals(name)) { // 识别唤醒词报错
+ WakeUpResult result = WakeUpResult.parseJson(name, params);
+ int errorCode = result.getErrorCode();
+ if (result.hasError()) {
+ listener.onError(errorCode, "", result);
+ }
+ } else if (SpeechConstant.CALLBACK_EVENT_WAKEUP_STOPED.equals(name)) { // 关闭唤醒词
+ listener.onStop();
+ } else if (SpeechConstant.CALLBACK_EVENT_WAKEUP_AUDIO.equals(name)) { // 音频回调
+ listener.onASrAudio(data, offset, length);
+ }
+ }
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/listener/IWakeupListener.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/listener/IWakeupListener.java
new file mode 100644
index 0000000..866c372
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/listener/IWakeupListener.java
@@ -0,0 +1,19 @@
+package com.baidu.aip.asrwakeup3.core.wakeup.listener;
+
+import com.baidu.aip.asrwakeup3.core.wakeup.WakeUpResult;
+
+/**
+ * Created by fujiayi on 2017/6/21.
+ */
+
+public interface IWakeupListener {
+
+
+ void onSuccess(String word, WakeUpResult result);
+
+ void onStop();
+
+ void onError(int errorCode, String errorMessge, WakeUpResult result);
+
+ void onASrAudio(byte[] data, int offset, int length);
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/listener/RecogWakeupListener.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/listener/RecogWakeupListener.java
new file mode 100644
index 0000000..31499d8
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/listener/RecogWakeupListener.java
@@ -0,0 +1,26 @@
+package com.baidu.aip.asrwakeup3.core.wakeup.listener;
+
+import android.os.Handler;
+import com.baidu.aip.asrwakeup3.core.recog.IStatus;
+import com.baidu.aip.asrwakeup3.core.wakeup.WakeUpResult;
+
+/**
+ * Created by fujiayi on 2017/9/21.
+ */
+
+public class RecogWakeupListener extends SimpleWakeupListener implements IStatus {
+
+ private static final String TAG = "RecogWakeupListener";
+
+ private Handler handler;
+
+ public RecogWakeupListener(Handler handler) {
+ this.handler = handler;
+ }
+
+ @Override
+ public void onSuccess(String word, WakeUpResult result) {
+ super.onSuccess(word, result);
+ handler.sendMessage(handler.obtainMessage(STATUS_WAKEUP_SUCCESS));
+ }
+}
diff --git a/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/listener/SimpleWakeupListener.java b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/listener/SimpleWakeupListener.java
new file mode 100644
index 0000000..e9390a0
--- /dev/null
+++ b/src/Notes-master3/core/src/main/java/com/baidu/aip/asrwakeup3/core/wakeup/listener/SimpleWakeupListener.java
@@ -0,0 +1,35 @@
+package com.baidu.aip.asrwakeup3.core.wakeup.listener;
+
+
+import com.baidu.aip.asrwakeup3.core.util.MyLogger;
+import com.baidu.aip.asrwakeup3.core.wakeup.WakeUpResult;
+
+/**
+ * Created by fujiayi on 2017/6/21.
+ */
+
+public class SimpleWakeupListener implements IWakeupListener {
+
+ private static final String TAG = "SimpleWakeupListener";
+
+ @Override
+ public void onSuccess(String word, WakeUpResult result) {
+ MyLogger.info(TAG, "唤醒成功,唤醒词:" + word);
+ }
+
+ @Override
+ public void onStop() {
+ MyLogger.info(TAG, "唤醒词识别结束:");
+ }
+
+ @Override
+ public void onError(int errorCode, String errorMessge, WakeUpResult result) {
+ MyLogger.info(TAG, "唤醒错误:" + errorCode + ";错误消息:" + errorMessge + "; 原始返回" + result.getOrigalJson());
+ }
+
+ @Override
+ public void onASrAudio(byte[] data, int offset, int length) {
+ MyLogger.error(TAG, "audio data: " + data.length);
+ }
+
+}
diff --git a/src/Notes-master3/core/src/main/jniLibs/arm64-v8a/libBaiduSpeechSDK.so b/src/Notes-master3/core/src/main/jniLibs/arm64-v8a/libBaiduSpeechSDK.so
new file mode 100644
index 0000000..2f16021
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/arm64-v8a/libBaiduSpeechSDK.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/arm64-v8a/libbdEASRAndroid.so b/src/Notes-master3/core/src/main/jniLibs/arm64-v8a/libbdEASRAndroid.so
new file mode 100644
index 0000000..c824ce9
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/arm64-v8a/libbdEASRAndroid.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/arm64-v8a/libbdSpilWakeup.so b/src/Notes-master3/core/src/main/jniLibs/arm64-v8a/libbdSpilWakeup.so
new file mode 100644
index 0000000..a481633
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/arm64-v8a/libbdSpilWakeup.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/arm64-v8a/libbd_easr_s1_merge_normal_20151216.dat.so b/src/Notes-master3/core/src/main/jniLibs/arm64-v8a/libbd_easr_s1_merge_normal_20151216.dat.so
new file mode 100644
index 0000000..826c81f
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/arm64-v8a/libbd_easr_s1_merge_normal_20151216.dat.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/arm64-v8a/libvad.dnn.so b/src/Notes-master3/core/src/main/jniLibs/arm64-v8a/libvad.dnn.so
new file mode 100644
index 0000000..0550061
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/arm64-v8a/libvad.dnn.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/armeabi-v7a/libBaiduSpeechSDK.so b/src/Notes-master3/core/src/main/jniLibs/armeabi-v7a/libBaiduSpeechSDK.so
new file mode 100644
index 0000000..5538ab6
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/armeabi-v7a/libBaiduSpeechSDK.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/armeabi-v7a/libbdEASRAndroid.so b/src/Notes-master3/core/src/main/jniLibs/armeabi-v7a/libbdEASRAndroid.so
new file mode 100644
index 0000000..0fef52a
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/armeabi-v7a/libbdEASRAndroid.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/armeabi-v7a/libbdSpilWakeup.so b/src/Notes-master3/core/src/main/jniLibs/armeabi-v7a/libbdSpilWakeup.so
new file mode 100644
index 0000000..f7809e2
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/armeabi-v7a/libbdSpilWakeup.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/armeabi-v7a/libbd_easr_s1_merge_normal_20151216.dat.so b/src/Notes-master3/core/src/main/jniLibs/armeabi-v7a/libbd_easr_s1_merge_normal_20151216.dat.so
new file mode 100644
index 0000000..826c81f
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/armeabi-v7a/libbd_easr_s1_merge_normal_20151216.dat.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/armeabi-v7a/libvad.dnn.so b/src/Notes-master3/core/src/main/jniLibs/armeabi-v7a/libvad.dnn.so
new file mode 100644
index 0000000..0550061
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/armeabi-v7a/libvad.dnn.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/armeabi/libBaiduSpeechSDK.so b/src/Notes-master3/core/src/main/jniLibs/armeabi/libBaiduSpeechSDK.so
new file mode 100644
index 0000000..a31b2ff
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/armeabi/libBaiduSpeechSDK.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/armeabi/libbdEASRAndroid.so b/src/Notes-master3/core/src/main/jniLibs/armeabi/libbdEASRAndroid.so
new file mode 100644
index 0000000..27509cb
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/armeabi/libbdEASRAndroid.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/armeabi/libbdSpilWakeup.so b/src/Notes-master3/core/src/main/jniLibs/armeabi/libbdSpilWakeup.so
new file mode 100644
index 0000000..a93b4e2
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/armeabi/libbdSpilWakeup.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/armeabi/libbd_easr_s1_merge_normal_20151216.dat.so b/src/Notes-master3/core/src/main/jniLibs/armeabi/libbd_easr_s1_merge_normal_20151216.dat.so
new file mode 100644
index 0000000..826c81f
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/armeabi/libbd_easr_s1_merge_normal_20151216.dat.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/armeabi/libvad.dnn.so b/src/Notes-master3/core/src/main/jniLibs/armeabi/libvad.dnn.so
new file mode 100644
index 0000000..0550061
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/armeabi/libvad.dnn.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/x86/libBaiduSpeechSDK.so b/src/Notes-master3/core/src/main/jniLibs/x86/libBaiduSpeechSDK.so
new file mode 100644
index 0000000..5de5f75
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/x86/libBaiduSpeechSDK.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/x86/libbdEASRAndroid.so b/src/Notes-master3/core/src/main/jniLibs/x86/libbdEASRAndroid.so
new file mode 100644
index 0000000..f254499
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/x86/libbdEASRAndroid.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/x86/libbdSpilWakeup.so b/src/Notes-master3/core/src/main/jniLibs/x86/libbdSpilWakeup.so
new file mode 100644
index 0000000..19175de
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/x86/libbdSpilWakeup.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/x86/libbd_easr_s1_merge_normal_20151216.dat.so b/src/Notes-master3/core/src/main/jniLibs/x86/libbd_easr_s1_merge_normal_20151216.dat.so
new file mode 100644
index 0000000..826c81f
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/x86/libbd_easr_s1_merge_normal_20151216.dat.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/x86/libvad.dnn.so b/src/Notes-master3/core/src/main/jniLibs/x86/libvad.dnn.so
new file mode 100644
index 0000000..0550061
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/x86/libvad.dnn.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/x86_64/libBaiduSpeechSDK.so b/src/Notes-master3/core/src/main/jniLibs/x86_64/libBaiduSpeechSDK.so
new file mode 100644
index 0000000..82ac641
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/x86_64/libBaiduSpeechSDK.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/x86_64/libbdEASRAndroid.so b/src/Notes-master3/core/src/main/jniLibs/x86_64/libbdEASRAndroid.so
new file mode 100644
index 0000000..c4b6ac2
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/x86_64/libbdEASRAndroid.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/x86_64/libbdSpilWakeup.so b/src/Notes-master3/core/src/main/jniLibs/x86_64/libbdSpilWakeup.so
new file mode 100644
index 0000000..25c10ff
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/x86_64/libbdSpilWakeup.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/x86_64/libbd_easr_s1_merge_normal_20151216.dat.so b/src/Notes-master3/core/src/main/jniLibs/x86_64/libbd_easr_s1_merge_normal_20151216.dat.so
new file mode 100644
index 0000000..826c81f
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/x86_64/libbd_easr_s1_merge_normal_20151216.dat.so differ
diff --git a/src/Notes-master3/core/src/main/jniLibs/x86_64/libvad.dnn.so b/src/Notes-master3/core/src/main/jniLibs/x86_64/libvad.dnn.so
new file mode 100644
index 0000000..0550061
Binary files /dev/null and b/src/Notes-master3/core/src/main/jniLibs/x86_64/libvad.dnn.so differ
diff --git a/src/Notes-master3/core/src/main/res/layout/common_mini.xml b/src/Notes-master3/core/src/main/res/layout/common_mini.xml
new file mode 100644
index 0000000..e381d13
--- /dev/null
+++ b/src/Notes-master3/core/src/main/res/layout/common_mini.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Notes-master3/core/src/main/res/values/strings.xml b/src/Notes-master3/core/src/main/res/values/strings.xml
new file mode 100644
index 0000000..4862f83
--- /dev/null
+++ b/src/Notes-master3/core/src/main/res/values/strings.xml
@@ -0,0 +1,3 @@
+
+ BaseAsr
+
diff --git a/src/Notes-master3/gradle.properties b/src/Notes-master3/gradle.properties
new file mode 100644
index 0000000..d015431
--- /dev/null
+++ b/src/Notes-master3/gradle.properties
@@ -0,0 +1,2 @@
+android.useAndroidX=true
+android.enableJetifier=true
\ No newline at end of file
diff --git a/src/Notes-master3/gradle.properties.properties b/src/Notes-master3/gradle.properties.properties
new file mode 100644
index 0000000..e69de29
diff --git a/src/Notes-master3/gradle/wrapper/gradle.properties b/src/Notes-master3/gradle/wrapper/gradle.properties
new file mode 100644
index 0000000..dab7c28
--- /dev/null
+++ b/src/Notes-master3/gradle/wrapper/gradle.properties
@@ -0,0 +1,21 @@
+# Project-wide Gradle settings.
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+# AndroidX package structure to make it clearer which packages are bundled with the
+# Android operating system, and which are packaged with your app"s APK
+# https://developer.android.com/topic/libraries/support-library/androidx-rn
+android.useAndroidX=true
+# Enables namespacing of each library's R class so that its R class includes only the
+# resources declared in the library itself and none from the library's dependencies,
+# thereby reducing the size of the R class for that library
+android.nonTransitiveRClass=true
\ No newline at end of file
diff --git a/src/Notes-master3/settings.gradle b/src/Notes-master3/settings.gradle
index e7b4def..22b1fb3 100644
--- a/src/Notes-master3/settings.gradle
+++ b/src/Notes-master3/settings.gradle
@@ -1 +1,5 @@
include ':app'
+<<<<<<< HEAD
+=======
+include ':core'
+>>>>>>> xiaojinchi_branch