Skip to content

Commit

Permalink
2023.02.09
Browse files Browse the repository at this point in the history
1、降低音量识别阈值;
2、修改ngrok是否开启判断逻辑;
3、修改js uuid 生成方式;
4、优化android demo:破音问题、服务运行状态判断问题。
  • Loading branch information
xszyou committed Feb 9, 2023
1 parent 9067b05 commit cfd4a3f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,6 @@ python main.py

技术交流群

<img src="images/-1101731868-3469777.png" alt="微信群">
<img src="images/20230209125339.jpg" alt="微信群">


Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ public void onReceive(Context context, Intent intent) {
int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1);
if (AudioManager.SCO_AUDIO_STATE_CONNECTED == state) {
Log.d("fay", "蓝牙sco连接成功");
mAudioManager.setBluetoothScoOn(true);
mAudioManager.setMode(mAudioManager.MODE_IN_CALL);


}
}
Expand Down Expand Up @@ -133,6 +132,7 @@ record = new AudioRecord(MediaRecorder.AudioSource.MIC,
Log.d("fay", "fay控制器连接成功");
} catch (IOException e) {
Log.d("fay", "socket连接失败");
running = false;
return;
}
byte[] data = new byte[1024];
Expand Down Expand Up @@ -168,7 +168,9 @@ record = null;
socket.close();
} catch (Exception e) {
}
Log.d("fay", "结束");
socket = null;
Log.d("fay", "send线程结束");

}

}
Expand All @@ -191,9 +193,11 @@ public void run() {
Log.d("fay", "开始接收音频文件");
String filedata = "";
data = new byte[1024];
while (data != null && data.length > 0) {
in.read(data);
filedata += MainActivity.bytesToHexString(data);
int len = 0;
while ((len = in.read(data)) != -1) {
byte[] temp = new byte[len];
System.arraycopy(data, 0, temp, 0, len);
filedata += MainActivity.bytesToHexString(temp);
int index = filedata.indexOf("080706050403020100");
if (filedata.length() > 9 && index > 0) {//wav文件结束标记
filedata = filedata.substring(0, index).replaceAll("F0F1F2F3F4F5F6F7F8", "");
Expand Down Expand Up @@ -234,6 +238,7 @@ public void onCompletion(MediaPlayer mp) {
mp.release();
mAudioManager.startBluetoothSco();
mAudioManager.setMode(mAudioManager.MODE_IN_CALL);
mAudioManager.setBluetoothScoOn(true);


}
Expand Down Expand Up @@ -268,6 +273,7 @@ public void onCompletion(MediaPlayer mp) {
} catch (Exception e) {//通过异常判断socket已经关闭,退出循环

} finally {
Log.d("fay", "rece线程结束");

}
}
Expand All @@ -292,7 +298,7 @@ public void run() {
}catch (Exception e){
Log.e("fay", e.toString());
}finally {
FayConnectorService.this.stopForeground(true);
FayConnectorService.this.stopSelf();
}
}
}).start();
Expand Down
3 changes: 1 addition & 2 deletions core/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, fay):
self.__processing = False
self.__history_level = []
self.__history_data = []
self.__dynamic_threshold = 0.5 # 声音识别的音量阈值
self.__dynamic_threshold = 0.35 # 声音识别的音量阈值

self.__MAX_LEVEL = 25000
self.__MAX_BLOCK = 100
Expand Down Expand Up @@ -147,7 +147,6 @@ def __record(self):



print("接收完成:{}".format(self.total))


def set_processing(self, processing):
Expand Down
13 changes: 8 additions & 5 deletions fay_booter.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ def __init__(self, fei):
super().__init__(fei)
self.__running = True
self.ngrok = None
self.streamCache = None
self.thread = MyThread(target=self.run)
self.thread.start() #启动远程音频输入设备监听线程

def run(self):
#启动ngork
if config_util.key_ngrok_cc_id is not None and config_util.key_ngrok_cc_id != "":
MyThread(target=self.start_ngrok, args=[config_util.key_ngrok_cc_id]).start()

self.streamCache = stream_util.StreamCache(1024*1024*20)
if config_util.key_ngrok_cc_id and config_util.key_ngrok_cc_id is not None and config_util.key_ngrok_cc_id.strip() != "":
MyThread(target=self.start_ngrok, args=[config_util.key_ngrok_cc_id]).start()
addr = None
while self.__running:
try:
Expand All @@ -125,15 +125,18 @@ def on_speaking(self, text):
feiFei.on_interact(interact)
time.sleep(2)

#recorder会等待stream不为空才开始录音
def get_stream(self):
while feiFei.deviceConnect is None:
while self.streamCache is None:
time.sleep(1)
pass
return self.streamCache

def stop(self):
super().stop()
self.__running = False
self.ngrok.stop()
if config_util.key_ngrok_cc_id and config_util.key_ngrok_cc_id is not None and config_util.key_ngrok_cc_id.strip() != "":
self.ngrok.stop()

def start_ngrok(self, clientId):
self.ngrok = ngrok_util.NgrokCilent(clientId)
Expand Down
11 changes: 1 addition & 10 deletions gui/static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,7 @@ new Vue({
return this.isEmptyItem(this.items_data[this.items_data.length - 1])
},
uuid() {
let s = []
let hexDigits = '0123456789abcdef'
for (let i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)
}
s[14] = '4' // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1) // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = '-'

let uuid = s.join('')
let uuid = Math.random().toString(36);
return uuid
},
runnnable() {
Expand Down
Binary file added images/20230209125339.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cfd4a3f

Please sign in to comment.