2023.02.09

1、降低音量识别阈值;
2、修改ngrok是否开启判断逻辑;
3、修改js uuid 生成方式;
4、优化android demo:破音问题、服务运行状态判断问题。
This commit is contained in:
xszyou 2023-02-09 12:55:16 +08:00
parent 9067b05ef1
commit cfd4a3fbbd
6 changed files with 24 additions and 25 deletions

View File

@ -273,6 +273,6 @@ python main.py
技术交流群 技术交流群
<img src="images/-1101731868-3469777.png" alt="微信群"> <img src="images/20230209125339.jpg" alt="微信群">

View File

@ -99,8 +99,7 @@ public class FayConnectorService extends Service {
int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1); int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1);
if (AudioManager.SCO_AUDIO_STATE_CONNECTED == state) { if (AudioManager.SCO_AUDIO_STATE_CONNECTED == state) {
Log.d("fay", "蓝牙sco连接成功"); Log.d("fay", "蓝牙sco连接成功");
mAudioManager.setBluetoothScoOn(true);
mAudioManager.setMode(mAudioManager.MODE_IN_CALL);
} }
} }
@ -133,6 +132,7 @@ public class FayConnectorService extends Service {
Log.d("fay", "fay控制器连接成功"); Log.d("fay", "fay控制器连接成功");
} catch (IOException e) { } catch (IOException e) {
Log.d("fay", "socket连接失败"); Log.d("fay", "socket连接失败");
running = false;
return; return;
} }
byte[] data = new byte[1024]; byte[] data = new byte[1024];
@ -168,7 +168,9 @@ public class FayConnectorService extends Service {
socket.close(); socket.close();
} catch (Exception e) { } catch (Exception e) {
} }
Log.d("fay", "结束"); socket = null;
Log.d("fay", "send线程结束");
} }
} }
@ -191,9 +193,11 @@ public class FayConnectorService extends Service {
Log.d("fay", "开始接收音频文件"); Log.d("fay", "开始接收音频文件");
String filedata = ""; String filedata = "";
data = new byte[1024]; data = new byte[1024];
while (data != null && data.length > 0) { int len = 0;
in.read(data); while ((len = in.read(data)) != -1) {
filedata += MainActivity.bytesToHexString(data); byte[] temp = new byte[len];
System.arraycopy(data, 0, temp, 0, len);
filedata += MainActivity.bytesToHexString(temp);
int index = filedata.indexOf("080706050403020100"); int index = filedata.indexOf("080706050403020100");
if (filedata.length() > 9 && index > 0) {//wav文件结束标记 if (filedata.length() > 9 && index > 0) {//wav文件结束标记
filedata = filedata.substring(0, index).replaceAll("F0F1F2F3F4F5F6F7F8", ""); filedata = filedata.substring(0, index).replaceAll("F0F1F2F3F4F5F6F7F8", "");
@ -234,6 +238,7 @@ public class FayConnectorService extends Service {
mp.release(); mp.release();
mAudioManager.startBluetoothSco(); mAudioManager.startBluetoothSco();
mAudioManager.setMode(mAudioManager.MODE_IN_CALL); mAudioManager.setMode(mAudioManager.MODE_IN_CALL);
mAudioManager.setBluetoothScoOn(true);
} }
@ -268,6 +273,7 @@ public class FayConnectorService extends Service {
} catch (Exception e) {//通过异常判断socket已经关闭退出循环 } catch (Exception e) {//通过异常判断socket已经关闭退出循环
} finally { } finally {
Log.d("fay", "rece线程结束");
} }
} }
@ -292,7 +298,7 @@ public class FayConnectorService extends Service {
}catch (Exception e){ }catch (Exception e){
Log.e("fay", e.toString()); Log.e("fay", e.toString());
}finally { }finally {
FayConnectorService.this.stopForeground(true); FayConnectorService.this.stopSelf();
} }
} }
}).start(); }).start();

View File

@ -32,7 +32,7 @@ class Recorder:
self.__processing = False self.__processing = False
self.__history_level = [] self.__history_level = []
self.__history_data = [] self.__history_data = []
self.__dynamic_threshold = 0.5 # 声音识别的音量阈值 self.__dynamic_threshold = 0.35 # 声音识别的音量阈值
self.__MAX_LEVEL = 25000 self.__MAX_LEVEL = 25000
self.__MAX_BLOCK = 100 self.__MAX_BLOCK = 100
@ -147,7 +147,6 @@ class Recorder:
print("接收完成:{}".format(self.total))
def set_processing(self, processing): def set_processing(self, processing):

View File

@ -94,15 +94,15 @@ class DeviceInputListener(Recorder):
super().__init__(fei) super().__init__(fei)
self.__running = True self.__running = True
self.ngrok = None self.ngrok = None
self.streamCache = None
self.thread = MyThread(target=self.run) self.thread = MyThread(target=self.run)
self.thread.start() #启动远程音频输入设备监听线程 self.thread.start() #启动远程音频输入设备监听线程
def run(self): def run(self):
#启动ngork #启动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) 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 addr = None
while self.__running: while self.__running:
try: try:
@ -125,15 +125,18 @@ class DeviceInputListener(Recorder):
feiFei.on_interact(interact) feiFei.on_interact(interact)
time.sleep(2) time.sleep(2)
#recorder会等待stream不为空才开始录音
def get_stream(self): def get_stream(self):
while feiFei.deviceConnect is None: while self.streamCache is None:
time.sleep(1)
pass pass
return self.streamCache return self.streamCache
def stop(self): def stop(self):
super().stop() super().stop()
self.__running = False 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): def start_ngrok(self, clientId):
self.ngrok = ngrok_util.NgrokCilent(clientId) self.ngrok = ngrok_util.NgrokCilent(clientId)

View File

@ -386,16 +386,7 @@ new Vue({
return this.isEmptyItem(this.items_data[this.items_data.length - 1]) return this.isEmptyItem(this.items_data[this.items_data.length - 1])
}, },
uuid() { uuid() {
let s = [] let uuid = Math.random().toString(36);
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('')
return uuid return uuid
}, },
runnnable() { runnnable() {

BIN
images/20230209125339.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 KiB