实现了循环提问回答
This commit is contained in:
parent
21708583b2
commit
eb5395b9e8
|
|
@ -198,7 +198,6 @@
|
|||
<Add option="../../../../../include_lib/newlib/pi32v2-lib/libm.a" />
|
||||
<Add option="../../../../../include_lib/newlib/pi32v2-lib/libc.a" />
|
||||
<Add option="../../../../../include_lib/newlib/pi32v2-lib/libcompiler_rt.a" />
|
||||
<Add option="--start-group" />
|
||||
<Add option="../../../../../cpu/wl82/liba/fs.a" />
|
||||
<Add option="../../../../../cpu/wl82/liba/event.a" />
|
||||
<Add option="../../../../../cpu/wl82/liba/system.a" />
|
||||
|
|
@ -277,16 +276,12 @@
|
|||
<Add option="../../../../../cpu/wl82/liba/lwip_2_1_3.a" />
|
||||
<Add option="../../../../../cpu/wl82/liba/wl_wifi.a" />
|
||||
<Add option="--end-group" />
|
||||
<Add option="../../../../../include_lib/c++/libstdc++/libemutls.a" />
|
||||
<Add option="../../../../../include_lib/c++/libstdc++/libc++.a" />
|
||||
<Add option="../../../../../include_lib/c++/libstdc++/libc++abi.a" />
|
||||
<Add option="../../../../../cpu/wl82/liba/ui.a" />
|
||||
<Add option="../../../../../cpu/wl82/liba/res.a" />
|
||||
<Add option="../../../../../cpu/wl82/liba/font.a" />
|
||||
<Add option="../../../../../cpu/wl82/liba/ui_draw.a" />
|
||||
<Add option="-T../../../../../cpu/wl82/sdk.ld" />
|
||||
<Add option="-M=../../../../../cpu/wl82/tools/sdk.map" />
|
||||
<Add option="--end-group" />
|
||||
</Linker>
|
||||
<ExtraCommands>
|
||||
<Add before="$compiler $options $includes -D__LD__ -E -P ..\..\..\..\..\cpu\wl82\sdk_used_list.c -o ..\..\..\..\..\cpu\wl82\sdk_used_list.used" />
|
||||
|
|
@ -4180,27 +4175,12 @@
|
|||
</Unit>
|
||||
<Unit filename="../../../../wifi_daobao/aduio_playback.h" />
|
||||
<Unit filename="../../../../wifi_daobao/aduio_record.h" />
|
||||
<Unit filename="../../../../wifi_daobao/aduio_record_queue.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="../../../../wifi_daobao/aduio_record_queue_new.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="../../../../wifi_daobao/chat_lwip_http.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="../../../../wifi_daobao/chat_lwip_http_old.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="../../../../wifi_daobao/chat_lwip_http_stream.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="../../../../wifi_daobao/chat_lwip_http_stream_demo.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="../../../../wifi_daobao/stt_websocket_local.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="../../../../wifi_daobao/stt_websocket_queue.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -18,7 +18,7 @@
|
|||
#include "asm/sfc_norflash_api.h"
|
||||
#include "event/device_event.h"
|
||||
|
||||
//#define PLAYBACK
|
||||
#define PLAYBACK
|
||||
#ifdef PLAYBACK
|
||||
|
||||
#define CONFIG_STORE_VOLUME
|
||||
|
|
@ -48,6 +48,8 @@ static int w_flag=0;
|
|||
|
||||
static int curlen=0;
|
||||
|
||||
extern OS_SEM voice_stop_sem;
|
||||
|
||||
static int audio_vfs_fread(void *file, void *data, u32 len)
|
||||
{
|
||||
cbuffer_t *cbuf = (cbuffer_t *)file;
|
||||
|
|
@ -107,6 +109,16 @@ static int playback_buffer_data_out(void)
|
|||
|
||||
}
|
||||
|
||||
static int audio_buffer_dec_stop(void)
|
||||
{
|
||||
int err = 0;
|
||||
union audio_req req = {0};
|
||||
|
||||
req.dec.cmd = AUDIO_DEC_STOP;
|
||||
server_request(pbh->dec_server, AUDIO_REQ_DEC, &req);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dec_server_event_handler(void *priv, int argc, int *argv)
|
||||
{
|
||||
|
|
@ -117,6 +129,9 @@ static void dec_server_event_handler(void *priv, int argc, int *argv)
|
|||
w_flag = 0;
|
||||
curlen = 0;
|
||||
printf("playback: AUDIO_SERVER_EVENT_END\n");
|
||||
audio_buffer_dec_stop();
|
||||
os_sem_set(&voice_stop_sem,0);
|
||||
os_sem_post(&voice_stop_sem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -185,7 +200,7 @@ static void read_queue_to_cbuf(void *priv)
|
|||
|
||||
free(recv);
|
||||
|
||||
if(w_flag==2){
|
||||
if(w_flag==1){
|
||||
os_sem_set(&pbh->w_sem,0);
|
||||
os_sem_post(&pbh->w_sem);
|
||||
}
|
||||
|
|
@ -194,7 +209,7 @@ static void read_queue_to_cbuf(void *priv)
|
|||
|
||||
static void playback_buffer_data_in(void)
|
||||
{
|
||||
thread_fork("read_queue_to_cbuf", 20, 1024 * 5, 1024 * 2, NULL, read_queue_to_cbuf, NULL);
|
||||
thread_fork("read_queue_to_cbuf", 20, 1024 * 3, 1024 * 2, NULL, read_queue_to_cbuf, NULL);
|
||||
}
|
||||
|
||||
static void playback_start(void *priv)
|
||||
|
|
@ -205,6 +220,7 @@ static void playback_start(void *priv)
|
|||
|
||||
while(1){
|
||||
os_sem_pend(&pbh->w_sem,0);
|
||||
os_time_dly(50);
|
||||
playback_buffer_data_out();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
#include "device/device.h"
|
||||
#include "asm/clock.h"
|
||||
|
||||
#define SPEECH_RECOGNITION_BUFFER_SIZE (10*1024)
|
||||
#define SPEECH_RECOGNITION_BUFFER_SIZE (1024 * 5)
|
||||
|
||||
#define APP_TIMER_CLK clk_get("osc") //获得时钟源
|
||||
#define MAX_TIME_CNT 0x7fff //最大计数值
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
#ifdef RECORD
|
||||
|
||||
//全局变量
|
||||
OS_SEM voice_start_sem;
|
||||
|
||||
OS_SEM voice_stop_sem;
|
||||
|
||||
static const u32 timer_div[] = {
|
||||
/*0000*/ 1,
|
||||
|
|
@ -66,8 +67,8 @@ static int record_vfs_fwrite(void *file, void *data, u32 len)
|
|||
__this->start_flag = 0;
|
||||
__this->stop_flag = 0;
|
||||
qmsg->end = 1;
|
||||
os_sem_set(&__this->stop_sem,0);
|
||||
os_sem_post(&__this->stop_sem);
|
||||
os_sem_set(&voice_stop_sem,0);
|
||||
os_sem_post(&voice_stop_sem);
|
||||
}
|
||||
else
|
||||
qmsg->end = 0;
|
||||
|
|
@ -133,8 +134,6 @@ static void enc_server_event_handler(void *priv, int argc, int *argv)
|
|||
case AUDIO_SERVER_EVENT_SPEAK_START:
|
||||
log_i("speak start ! \n");
|
||||
__this->start_flag = 1;
|
||||
os_sem_set(&voice_start_sem,0);
|
||||
os_sem_post(&voice_start_sem);
|
||||
break;
|
||||
case AUDIO_SERVER_EVENT_SPEAK_STOP:
|
||||
log_i("speak stop ! \n");
|
||||
|
|
@ -156,8 +155,7 @@ static int encoder_init(int sample_rate, u8 channel)
|
|||
channel = 2;
|
||||
}
|
||||
|
||||
os_sem_create(&__this->stop_sem, 0);
|
||||
os_sem_create(&voice_start_sem, 0);
|
||||
os_sem_create(&voice_stop_sem, 0);
|
||||
|
||||
__this->start_flag = 0;
|
||||
__this->stop_flag = 0;
|
||||
|
|
@ -222,7 +220,7 @@ static void record_run_task(void){
|
|||
record_mode_init();
|
||||
while(1){
|
||||
//等待信号量
|
||||
os_sem_pend(&__this->stop_sem, 0);
|
||||
os_sem_pend(&voice_stop_sem, 0);
|
||||
//os_time_dly(1000);
|
||||
req.enc.cmd = AUDIO_ENC_PP;
|
||||
server_request(__this->enc_server, AUDIO_REQ_ENC, &req);
|
||||
|
|
@ -232,7 +230,7 @@ static void record_run_task(void){
|
|||
|
||||
static void record_run_task_create(void)
|
||||
{
|
||||
thread_fork("record_run_task", 15, 1024 * 3 , 0, NULL, record_run_task, NULL);
|
||||
thread_fork("record_run_task", 20, 1024 , 0, NULL, record_run_task, NULL);
|
||||
}
|
||||
|
||||
static void record_start(void *priv)
|
||||
|
|
|
|||
|
|
@ -126,14 +126,8 @@ static void http_chat_task(void *priv)
|
|||
const char *server_name = "ark.cn-beijing.volces.com"; // 服务器名称
|
||||
u16_t port = 80; // 端口
|
||||
const char *uri = "/api/v3/chat/completions"; // 请求的 URI
|
||||
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddStringToObject(root, "model", "ep-20241018142738-n7wv9");
|
||||
|
||||
cJSON_AddBoolToObject(root, "stream", true);
|
||||
|
||||
cJSON *messages = cJSON_AddArrayToObject(root, "messages");
|
||||
int err;
|
||||
cJSON *root=NULL;
|
||||
|
||||
httpc_connection_t setting = { .use_proxy = 0,
|
||||
.result_fn = NULL,
|
||||
|
|
@ -143,12 +137,29 @@ static void http_chat_task(void *priv)
|
|||
.arglen = strlen(HTTP_DEMO_DATA),
|
||||
.args = HTTP_DEMO_DATA
|
||||
};
|
||||
|
||||
while(1){
|
||||
while(1){
|
||||
|
||||
os_sem_pend(&chat_sem, 0);
|
||||
|
||||
root = cJSON_CreateObject();
|
||||
if(!root){
|
||||
goto fail;
|
||||
}
|
||||
|
||||
cJSON_AddStringToObject(root, "model", "ep-20241018142738-n7wv9");
|
||||
|
||||
cJSON_AddBoolToObject(root, "stream", true);
|
||||
|
||||
cJSON *messages = cJSON_AddArrayToObject(root, "messages");
|
||||
if(!messages){
|
||||
goto fail;
|
||||
}
|
||||
|
||||
cJSON *session = cJSON_CreateObject();
|
||||
if(!session){
|
||||
goto fail;
|
||||
}
|
||||
|
||||
cJSON_AddStringToObject(session, "role", "user");
|
||||
|
||||
|
|
@ -170,7 +181,11 @@ static void http_chat_task(void *priv)
|
|||
|
||||
free(http_data);
|
||||
}
|
||||
|
||||
fail:
|
||||
if (!root) {
|
||||
cJSON_Delete(root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -188,7 +203,7 @@ static void http_chat_start(void *priv)
|
|||
os_time_dly(1000);
|
||||
}
|
||||
|
||||
if (thread_fork("http_chat_task", 10, 1024 * 10, 0, NULL, http_chat_task, NULL) != OS_NO_ERR) {
|
||||
if (thread_fork("http_chat_task", 20, 1024 * 4, 0, NULL, http_chat_task, NULL) != OS_NO_ERR) {
|
||||
printf("thread fork fail\n");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,6 +82,8 @@ extern OS_SEM voice_start_sem;
|
|||
|
||||
OS_SEM chat_sem;
|
||||
|
||||
static OS_SEM disconnet_sem;
|
||||
|
||||
unsigned char chat_msg[4 * 1024];
|
||||
|
||||
static void websockets_callback(u8 *buf, u32 len, u8 type)
|
||||
|
|
@ -113,7 +115,10 @@ static void websockets_callback(u8 *buf, u32 len, u8 type)
|
|||
if (cJSON_IsString(text) && (text->valuestring != NULL)) {
|
||||
printf("text: %s\r\n", (unsigned char*)text->valuestring);
|
||||
sprintf(chat_msg,"%s",text->valuestring);
|
||||
os_sem_set(&chat_sem,0);
|
||||
os_sem_post(&chat_sem);
|
||||
os_sem_set(&disconnet_sem,0);
|
||||
os_sem_post(&disconnet_sem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -140,6 +145,7 @@ static void websockets_client_reg(struct websocket_struct *websockets_info, char
|
|||
websockets_info->_recv_thread = websockets_client_socket_recv_thread;
|
||||
websockets_info->_heart_thread = websockets_client_socket_heart_thread;
|
||||
websockets_info->_recv_cb = websockets_callback;
|
||||
websockets_info->_exit_notify = websockets_client_notify_disconnet_to_server;
|
||||
websockets_info->_recv = NULL;
|
||||
|
||||
websockets_info->websocket_mode = mode;
|
||||
|
|
@ -177,6 +183,11 @@ static int websockets_client_send(struct websocket_struct *websockets_info, u8 *
|
|||
return websockets_info->_send(websockets_info, buf, len, type);
|
||||
}
|
||||
|
||||
static int websockets_client_exit_notify(struct websocket_struct *websockets_info)
|
||||
{
|
||||
return websockets_info->_exit_notify(websockets_info);
|
||||
}
|
||||
|
||||
static void websockets_client_exit(struct websocket_struct *websockets_info)
|
||||
{
|
||||
websockets_info->_exit(websockets_info);
|
||||
|
|
@ -388,6 +399,7 @@ static void generate_uuid(char *uuid_out)
|
|||
*******************************************************************************/
|
||||
static void websockets_stt_client_main_thread(void *priv)
|
||||
{
|
||||
reconnet:
|
||||
int err;
|
||||
char mode = WEBSOCKET_MODE;
|
||||
u8 url[256] = OBJ_URL;
|
||||
|
|
@ -404,6 +416,7 @@ static void websockets_stt_client_main_thread(void *priv)
|
|||
int msg[32]; //接收消息队列buf
|
||||
char *aduio_client_request=NULL;
|
||||
rec_msg *rmsg=NULL;
|
||||
int frist_voice=0;
|
||||
|
||||
AsrWsClient STTPayload={
|
||||
.appid="8571950639",
|
||||
|
|
@ -465,8 +478,15 @@ static void websockets_stt_client_main_thread(void *priv)
|
|||
|
||||
/* 5 . recv or send data */
|
||||
while(1){
|
||||
//接收信号量
|
||||
os_sem_pend(&voice_start_sem, 0); //获取信号量
|
||||
//接收消息队列
|
||||
err = os_taskq_pend("taskq", msg, ARRAY_SIZE(msg));
|
||||
if (err != OS_TASKQ || msg[0] != Q_USER) {
|
||||
goto exit_ws;
|
||||
}
|
||||
|
||||
rmsg=(rec_msg *)msg[1];
|
||||
|
||||
if(frist_voice==0){
|
||||
|
||||
websocket_header=generate_header(DEFAULT_HEADR);
|
||||
|
||||
|
|
@ -515,19 +535,9 @@ static void websockets_stt_client_main_thread(void *priv)
|
|||
|
||||
free(full_client_request);
|
||||
|
||||
//websockets_sleep(1000);
|
||||
|
||||
while(1){
|
||||
//接收消息队列
|
||||
err = os_taskq_pend("taskq", msg, ARRAY_SIZE(msg));
|
||||
if (err != OS_TASKQ || msg[0] != Q_USER) {
|
||||
goto exit_ws;
|
||||
frist_voice = 1;
|
||||
}
|
||||
|
||||
rmsg=(rec_msg *)msg[1];
|
||||
|
||||
//put_buf(rmsg->msg,rmsg->msg_size);
|
||||
|
||||
|
||||
if(rmsg->end){
|
||||
websocket_header=generate_header(STT_DEFAULT_VERSION,0b0010,0b0010,0b0000,\
|
||||
|
|
@ -558,8 +568,6 @@ static void websockets_stt_client_main_thread(void *priv)
|
|||
|
||||
free(websocket_header);
|
||||
|
||||
free(rmsg);
|
||||
|
||||
err = websockets_client_send(websockets_info, (u8 *)aduio_client_request, total_length, WCT_TXTDATA);
|
||||
if (FALSE == err) {
|
||||
printf(" . ! send err !!!\r\n");
|
||||
|
|
@ -568,9 +576,24 @@ static void websockets_stt_client_main_thread(void *priv)
|
|||
|
||||
free(aduio_client_request);
|
||||
|
||||
if(rmsg->end){
|
||||
free(rmsg);
|
||||
os_sem_pend(&disconnet_sem,0);
|
||||
|
||||
if (websockets_info->ping_thread_id) {
|
||||
thread_kill(&websockets_info->ping_thread_id, KILL_REQ);
|
||||
}
|
||||
if (websockets_info->recv_thread_id) {
|
||||
thread_kill(&websockets_info->recv_thread_id, KILL_REQ);
|
||||
}
|
||||
websockets_client_exit(websockets_info);
|
||||
free(websockets_info);
|
||||
|
||||
goto reconnet;
|
||||
}
|
||||
free(rmsg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exit_ws:
|
||||
/* 6 . exit */
|
||||
|
|
@ -599,12 +622,13 @@ exit_ws:
|
|||
|
||||
static void stt_websocket_client_thread_create(void)
|
||||
{
|
||||
thread_fork("websockets_stt_client_main_thread", 15, 1024 * 250, 256, 0, websockets_stt_client_main_thread, NULL);
|
||||
thread_fork("websockets_stt_client_main_thread", 20, 1024 * 6, 256, 0, websockets_stt_client_main_thread, NULL);
|
||||
}
|
||||
|
||||
static void stt_http_websocket_start(void *priv)
|
||||
{
|
||||
enum wifi_sta_connect_state state;
|
||||
os_sem_create(&disconnet_sem,0);
|
||||
while (1) {
|
||||
printf("Connecting to the network...\n");
|
||||
state = wifi_get_sta_connect_state();
|
||||
|
|
|
|||
|
|
@ -378,7 +378,7 @@ static void websockets_tts_client_main_thread(void *priv)
|
|||
.token="BNA-XBIrEisvMczcmc-Sm4B3H-PmfqlL",
|
||||
.uid="2452284000",
|
||||
.voice_type="BV700_streaming",
|
||||
.encoding="mp3",
|
||||
.encoding="pcm",
|
||||
.compression_rate=1,
|
||||
.rate=8000,
|
||||
.speed_ratio=1.0,
|
||||
|
|
@ -431,7 +431,7 @@ static void websockets_tts_client_main_thread(void *priv)
|
|||
websockets_info->_recv_thread,
|
||||
websockets_info);
|
||||
|
||||
websockets_sleep(1000);
|
||||
//websockets_sleep(1000);
|
||||
|
||||
/* 5 . recv or send data */
|
||||
while (1) {
|
||||
|
|
@ -530,7 +530,7 @@ exit_ws:
|
|||
|
||||
static void tts_websocket_client_thread_create(void)
|
||||
{
|
||||
thread_fork("websockets_tts_client_main_thread", 15, 1024 * 8, 1024, 0, websockets_tts_client_main_thread, NULL);
|
||||
thread_fork("websockets_tts_client_main_thread", 20, 1024 * 6, 1024, 0, websockets_tts_client_main_thread, NULL);
|
||||
}
|
||||
|
||||
static void tts_http_websocket_start(void *priv)
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue