device:rockchip:aispeech-4mic-32bit:support vad
Change-Id: I28a99191f6df65cc2824010367e91a97e88a8aa2 Signed-off-by: Sun ChuanHu <aaron.sun@rock-chips.com>
This commit is contained in:
@ -1,8 +1,8 @@
|
|||||||
arecord -D vad -c 8 -r 16000 -f S16_LE -d 1 -t raw /tmp/test.pcm
|
amixer cset name='vad switch' 1
|
||||||
rm /tmp/test.pcm
|
|
||||||
echo 0x60 0x40ff0050 > /sys/kernel/debug/vad/reg
|
echo 0x60 0x40ff0050 > /sys/kernel/debug/vad/reg
|
||||||
echo 0x5c 0x000e2080 > /sys/kernel/debug/vad/reg
|
echo 0x5c 0x000e2080 > /sys/kernel/debug/vad/reg
|
||||||
|
arecord -D 4mic_loopback -c 5 -r 16000 -f S16_LE -d 1 -t raw /tmp/test.pcm
|
||||||
|
rm /tmp/test.pcm
|
||||||
ln -s /oem/aispeech_softap_lite /data/aispeech_softap_lite
|
ln -s /oem/aispeech_softap_lite /data/aispeech_softap_lite
|
||||||
ln -s /oem/wifi_monitor.sh /data/
|
ln -s /oem/wifi_monitor.sh /data/
|
||||||
ln -s /oem/dds_client /data/dds_client
|
ln -s /oem/dds_client /data/dds_client
|
||||||
|
|||||||
@ -31,7 +31,7 @@
|
|||||||
static FILE *input_fd, *output_fd;
|
static FILE *input_fd, *output_fd;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char *dui_msg_table[] = {
|
const char *dui_msg_table[] = {
|
||||||
"RECORDER_CMD_START",
|
"RECORDER_CMD_START",
|
||||||
"RECORDER_CMD_STOP",
|
"RECORDER_CMD_STOP",
|
||||||
"PLAYER_CMD_PLAY",
|
"PLAYER_CMD_PLAY",
|
||||||
@ -195,7 +195,7 @@ static void recorder_run(void *args) {
|
|||||||
.channels = g_cfg.recorder.channels,
|
.channels = g_cfg.recorder.channels,
|
||||||
.samplerate = g_cfg.recorder.samplerate,
|
.samplerate = g_cfg.recorder.samplerate,
|
||||||
.device = g_cfg.recorder.device
|
.device = g_cfg.recorder.device
|
||||||
};
|
};
|
||||||
recorder_handle_t recorder = recorder_open(&cfg);
|
recorder_handle_t recorder = recorder_open(&cfg);
|
||||||
assert(recorder != NULL);
|
assert(recorder != NULL);
|
||||||
int block = cfg.bits * cfg.channels / 8;
|
int block = cfg.bits * cfg.channels / 8;
|
||||||
@ -216,7 +216,7 @@ static void recorder_run(void *args) {
|
|||||||
#elif defined(WAKEUP_FESPL)
|
#elif defined(WAKEUP_FESPL)
|
||||||
system("tinymix set 28 3");
|
system("tinymix set 28 3");
|
||||||
system("tinymix set 36 12");
|
system("tinymix set 36 12");
|
||||||
system("tinymix set 29 3");
|
system("tinymix set 29 3");
|
||||||
system("tinymix set 37 12");
|
system("tinymix set 37 12");
|
||||||
system("tinymix set 26 3");
|
system("tinymix set 26 3");
|
||||||
system("tinymix set 35 5");
|
system("tinymix set 35 5");
|
||||||
@ -227,7 +227,7 @@ static void recorder_run(void *args) {
|
|||||||
os_queue_send(user_listen_queue, &m);
|
os_queue_send(user_listen_queue, &m);
|
||||||
int frames, read_bytes;
|
int frames, read_bytes;
|
||||||
while (1) {
|
while (1) {
|
||||||
frames = recorder_read(recorder, read_buf, cfg.period_size);
|
frames = recorder_read(recorder, read_buf, cfg.period_size);
|
||||||
if (frames > 0) {
|
if (frames > 0) {
|
||||||
read_bytes = frames * block;
|
read_bytes = frames * block;
|
||||||
//OS_LOG_I(recorder, "read bytes: %d", read_bytes);
|
//OS_LOG_I(recorder, "read bytes: %d", read_bytes);
|
||||||
@ -259,7 +259,7 @@ static void player_run(void *args) {
|
|||||||
bool cancel = false;
|
bool cancel = false;
|
||||||
while (1) {
|
while (1) {
|
||||||
memset(&item, 0, sizeof(item));
|
memset(&item, 0, sizeof(item));
|
||||||
ret = os_queue_receive(player_queue, &m);
|
ret = os_queue_receive(player_queue, &m);
|
||||||
if (ret == -1) break;
|
if (ret == -1) break;
|
||||||
OS_LOG_I(player, "%s", dui_msg_table[m.type]);
|
OS_LOG_I(player, "%s", dui_msg_table[m.type]);
|
||||||
|
|
||||||
@ -343,7 +343,7 @@ static bool is_same_word(const char *s1, const char *s2) {
|
|||||||
s2++;
|
s2++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WAKEUP_FESPA
|
#ifdef WAKEUP_FESPA
|
||||||
@ -426,7 +426,7 @@ static void vad_run(void *args) {
|
|||||||
int read_bytes;
|
int read_bytes;
|
||||||
|
|
||||||
OS_LOG_I(vad, "START");
|
OS_LOG_I(vad, "START");
|
||||||
gettimeofday(&start_time, NULL);
|
gettimeofday(&start_time, NULL);
|
||||||
while (1) {
|
while (1) {
|
||||||
read_bytes = os_stream_read(vad_stream, read_buf, read_buf_size);
|
read_bytes = os_stream_read(vad_stream, read_buf, read_buf_size);
|
||||||
if (read_bytes == -1) {
|
if (read_bytes == -1) {
|
||||||
@ -463,7 +463,7 @@ static void vad_run(void *args) {
|
|||||||
if (info.status == 2) {
|
if (info.status == 2) {
|
||||||
//终止VAD输入缓冲写入
|
//终止VAD输入缓冲写入
|
||||||
duilite_vad_stop(vad_engine);
|
duilite_vad_stop(vad_engine);
|
||||||
|
|
||||||
//os_stream_finish(dds_stream);
|
//os_stream_finish(dds_stream);
|
||||||
os_stream_stop(vad_stream);
|
os_stream_stop(vad_stream);
|
||||||
|
|
||||||
@ -717,7 +717,7 @@ static void speech_to_wait_for_wakeup(void *args) {
|
|||||||
//终止VAD数据缓冲写入
|
//终止VAD数据缓冲写入
|
||||||
os_stream_stop(vad_stream);
|
os_stream_stop(vad_stream);
|
||||||
os_stream_stop(dds_stream);
|
os_stream_stop(dds_stream);
|
||||||
dui_msg_t m;
|
dui_msg_t m;
|
||||||
memset(&m, 0, sizeof(m));
|
memset(&m, 0, sizeof(m));
|
||||||
m.type = PLAYER_CMD_PLAY;
|
m.type = PLAYER_CMD_PLAY;
|
||||||
m.player.mode = PLAYER_MODE_PROMPT;
|
m.player.mode = PLAYER_MODE_PROMPT;
|
||||||
@ -725,7 +725,7 @@ static void speech_to_wait_for_wakeup(void *args) {
|
|||||||
m.player.native = true;
|
m.player.native = true;
|
||||||
m.player.need_free = false;
|
m.player.need_free = false;
|
||||||
m.player.end_session = true;
|
m.player.end_session = true;
|
||||||
os_queue_send(player_queue, &m);
|
os_queue_send(player_queue, &m);
|
||||||
OS_LOG_I(process, "=====");
|
OS_LOG_I(process, "=====");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -956,7 +956,7 @@ static char *msg_type_set[] = {
|
|||||||
"DDS_EV_OUT_ERROR",
|
"DDS_EV_OUT_ERROR",
|
||||||
"DDS_EV_OUT_ASR_RESULT",
|
"DDS_EV_OUT_ASR_RESULT",
|
||||||
"DDS_EV_OUT_DUI_RESPONSE",
|
"DDS_EV_OUT_DUI_RESPONSE",
|
||||||
"DDS_EV_OUT_DUI_LOGIN"
|
"DDS_EV_OUT_DUI_LOGIN"
|
||||||
};
|
};
|
||||||
|
|
||||||
static int process_tts(struct dds_msg *msg) {
|
static int process_tts(struct dds_msg *msg) {
|
||||||
@ -1141,7 +1141,7 @@ static int dui_parse_cfg(const char *cfg) {
|
|||||||
//auth
|
//auth
|
||||||
cJSON *auth_js = cJSON_GetObjectItem(js, "auth");
|
cJSON *auth_js = cJSON_GetObjectItem(js, "auth");
|
||||||
char *auth = cJSON_Print(auth_js);
|
char *auth = cJSON_Print(auth_js);
|
||||||
duilite_library_load(auth);
|
duilite_library_load(auth);
|
||||||
free(auth);
|
free(auth);
|
||||||
|
|
||||||
//recorder
|
//recorder
|
||||||
@ -1206,8 +1206,8 @@ static int dui_parse_cfg(const char *cfg) {
|
|||||||
|
|
||||||
int dui_library_init(const char *cfg, user_listen_cb listen) {
|
int dui_library_init(const char *cfg, user_listen_cb listen) {
|
||||||
#ifdef SAVE_AUDIO
|
#ifdef SAVE_AUDIO
|
||||||
input_fd = fopen("/tmp/1.pcm", "wb");
|
input_fd = fopen("/userdata/1.pcm", "wb");
|
||||||
output_fd = fopen("/tmp/2.pcm", "wb");
|
output_fd = fopen("/userdata/2.pcm", "wb");
|
||||||
#endif
|
#endif
|
||||||
if (0 != dui_parse_cfg(cfg)) return -1;
|
if (0 != dui_parse_cfg(cfg)) return -1;
|
||||||
os_log_init(NULL);
|
os_log_init(NULL);
|
||||||
@ -1243,7 +1243,7 @@ int dui_library_init(const char *cfg, user_listen_cb listen) {
|
|||||||
//500ms缓冲
|
//500ms缓冲
|
||||||
int recorder_stream_size = 5 * g_cfg.recorder.channels * (g_cfg.recorder.bits / 8) * (g_cfg.recorder.samplerate / 10);
|
int recorder_stream_size = 5 * g_cfg.recorder.channels * (g_cfg.recorder.bits / 8) * (g_cfg.recorder.samplerate / 10);
|
||||||
wakeup_stream = os_stream_create(recorder_stream_size);
|
wakeup_stream = os_stream_create(recorder_stream_size);
|
||||||
|
|
||||||
//200ms缓冲
|
//200ms缓冲
|
||||||
int vad_stream_size = 2 * (g_cfg.recorder.bits / 8) * (g_cfg.recorder.samplerate / 10);
|
int vad_stream_size = 2 * (g_cfg.recorder.bits / 8) * (g_cfg.recorder.samplerate / 10);
|
||||||
vad_stream = os_stream_create(vad_stream_size);
|
vad_stream = os_stream_create(vad_stream_size);
|
||||||
@ -1262,11 +1262,11 @@ int dui_library_init(const char *cfg, user_listen_cb listen) {
|
|||||||
//唤醒线程
|
//唤醒线程
|
||||||
c.run = wakeup_run;
|
c.run = wakeup_run;
|
||||||
wakeup_task = os_thread_create(&c);
|
wakeup_task = os_thread_create(&c);
|
||||||
|
|
||||||
//vad线程
|
//vad线程
|
||||||
c.run = vad_run;
|
c.run = vad_run;
|
||||||
vad_task = os_thread_create(&c);
|
vad_task = os_thread_create(&c);
|
||||||
|
|
||||||
//处理线程
|
//处理线程
|
||||||
c.run = process_run;
|
c.run = process_run;
|
||||||
process_task = os_thread_create(&c);
|
process_task = os_thread_create(&c);
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,7 +1,31 @@
|
|||||||
#include "dui.h"
|
#include "dui.h"
|
||||||
|
#include "dui_msg.h"
|
||||||
|
#include "os_thread.h"
|
||||||
|
#include "os_queue.h"
|
||||||
|
#include "os_event_group.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define EV_RECODER_CLOSE (1 << 0)
|
||||||
|
|
||||||
|
static os_event_group_handle_t event;
|
||||||
|
|
||||||
|
extern os_queue_handle_t user_listen_queue;
|
||||||
|
|
||||||
|
static void listen_cb(dui_msg_t *msg) {
|
||||||
|
dui_msg_t m;
|
||||||
|
int ret;
|
||||||
|
while (1) {
|
||||||
|
ret = os_queue_receive(user_listen_queue, &m);
|
||||||
|
if (ret == -1) break;
|
||||||
|
if (m.type == RECORDER_CMD_STOP) {
|
||||||
|
os_event_group_set_bits(event, EV_RECODER_CLOSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
FILE *fd = fopen(argv[1], "rb");
|
FILE *fd = fopen(argv[1], "rb");
|
||||||
@ -11,13 +35,40 @@ int main(int argc, char **argv) {
|
|||||||
fseek(fd, 0L, SEEK_SET);
|
fseek(fd, 0L, SEEK_SET);
|
||||||
fread(buf, 1, len, fd);
|
fread(buf, 1, len, fd);
|
||||||
|
|
||||||
|
event = os_event_group_create();
|
||||||
|
|
||||||
dui_library_init(buf, NULL);
|
dui_library_init(buf, listen_cb);
|
||||||
|
fclose(fd);
|
||||||
dui_start_recorder();
|
dui_start_recorder();
|
||||||
while (1) {
|
while (1) {
|
||||||
sleep(20);
|
int buf[64];
|
||||||
|
long frames;
|
||||||
|
while (1) {
|
||||||
|
struct timeval tv = {
|
||||||
|
.tv_usec = 50000
|
||||||
|
};
|
||||||
|
frames = -1;
|
||||||
|
fd = fopen("/sys/module/snd_soc_rockchip_vad/parameters/voice_inactive_frames", "r");
|
||||||
|
if (fd) {
|
||||||
|
if (fgets(buf, sizeof(buf), fd)) {
|
||||||
|
frames = atol(buf);
|
||||||
|
}
|
||||||
|
fclose(fd);
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
printf("\n frames = %d", frames);
|
||||||
|
|
||||||
|
if (frames > 80000) {
|
||||||
|
dui_stop_recorder();
|
||||||
|
os_event_group_wait_bits(event, EV_RECODER_CLOSE, true, true);
|
||||||
|
system("echo 0 > /sys/module/snd_soc_rockchip_vad/parameters/voice_inactive_frames");
|
||||||
|
system("echo mem > /sys/power/state");
|
||||||
|
// usleep(30 * 1000);
|
||||||
|
dui_start_recorder();
|
||||||
|
}
|
||||||
|
select(0, NULL, NULL, NULL, &tv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dui_stop_recorder();
|
|
||||||
dui_library_cleanup();
|
dui_library_cleanup();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@ -1,69 +0,0 @@
|
|||||||
#include "dui.h"
|
|
||||||
#include "dui_msg.h"
|
|
||||||
#include "dui_thread.h"
|
|
||||||
#include "dui_queue.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#define EV_RECODER_CLOSE (1 << 0)
|
|
||||||
|
|
||||||
static dui_event_group_handle_t event;
|
|
||||||
|
|
||||||
extern dui_queue_handle_t user_listen_queue;
|
|
||||||
|
|
||||||
static void listen_cb(dui_msg_t *msg) {
|
|
||||||
dui_msg_t m;
|
|
||||||
int ret;
|
|
||||||
while (1) {
|
|
||||||
ret = dui_queue_receive(user_listen_queue, &m);
|
|
||||||
if (ret == -1) break;
|
|
||||||
if (m.type == RECORDER_CMD_STOP) {
|
|
||||||
dui_event_group_set_bits(event, EV_RECODER_CLOSE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
|
||||||
FILE *fd = fopen(argv[1], "rb");
|
|
||||||
fseek(fd, 0L, SEEK_END);
|
|
||||||
int len = ftell(fd);
|
|
||||||
char *buf = (char *)malloc(len + 1);
|
|
||||||
fseek(fd, 0L, SEEK_SET);
|
|
||||||
fread(buf, 1, len, fd);
|
|
||||||
|
|
||||||
event = dui_event_group_create();
|
|
||||||
|
|
||||||
dui_library_init(buf, listen_cb);
|
|
||||||
fclose(fd);
|
|
||||||
dui_start_recorder();
|
|
||||||
while (1) {
|
|
||||||
int buf[64];
|
|
||||||
long frames;
|
|
||||||
while (1) {
|
|
||||||
struct timeval tv = {
|
|
||||||
.tv_usec = 50000
|
|
||||||
};
|
|
||||||
frames = -1;
|
|
||||||
fd = fopen("/sys/module/snd_soc_rockchip_vad/parameters/voice_inactive_frames", "r");
|
|
||||||
if (fd) {
|
|
||||||
if (fgets(buf, sizeof(buf), fd)) {
|
|
||||||
frames = atol(buf);
|
|
||||||
}
|
|
||||||
fclose(fd);
|
|
||||||
}
|
|
||||||
if (frames > 80000) {
|
|
||||||
dui_stop_recorder();
|
|
||||||
dui_event_group_wait_bits(event, EV_RECODER_CLOSE, true, true);
|
|
||||||
system("echo 0 > /sys/module/snd_soc_rockchip_vad/parameters/voice_inactive_frames");
|
|
||||||
system("echo mem > /sys/power/state");
|
|
||||||
dui_start_recorder();
|
|
||||||
}
|
|
||||||
select(0, NULL, NULL, NULL, &tv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dui_library_cleanup();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user