Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
car-controlserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenzhongjian
car-controlserver
Commits
e22b2880
Commit
e22b2880
authored
Nov 10, 2025
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入了tts播放,但是有bug,会一直播放
parent
5352b4df
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
284 additions
and
75 deletions
+284
-75
audio.mp3
audio.mp3
+0
-0
Makefile
build/Makefile
+27
-0
main
build/main
+0
-0
progress.marks
build/third_party/mosquitto/CMakeFiles/progress.marks
+1
-1
progress.make
...osquitto_ctrl/CMakeFiles/mosquitto_ctrl.dir/progress.make
+2
-2
progress.make
...y/mosquitto/lib/CMakeFiles/libmosquitto.dir/progress.make
+2
-2
progress.make
...itto/lib/CMakeFiles/libmosquitto_static.dir/progress.make
+6
-6
progress.make
...y/CMakeFiles/mosquitto_dynamic_security.dir/progress.make
+2
-2
progress.make
...arty/mosquitto/src/CMakeFiles/mosquitto.dir/progress.make
+19
-19
progress.marks
build/third_party/mosquitto/src/CMakeFiles/progress.marks
+1
-1
audioplay.c
drivers/sensors/audioplay.c
+4
-0
audiotts_play.c
drivers/sensors/audiotts_play.c
+186
-12
audiotts_play.h
drivers/sensors/audiotts_play.h
+10
-3
mqtt_infor_handle.c
modules/mqtt/mqtt_infor_handle.c
+4
-1
mqtt_init.c
modules/mqtt/mqtt_init.c
+20
-26
No files found.
audio.mp3
0 → 100644
View file @
e22b2880
File added
build/Makefile
View file @
e22b2880
...
...
@@ -1025,6 +1025,30 @@ drivers/sensors/audioplay.c.s:
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/sensors/audioplay.c.s
.PHONY
:
drivers/sensors/audioplay.c.s
drivers/sensors/audiotts_play.o
:
drivers/sensors/audiotts_play.c.o
.PHONY
:
drivers/sensors/audiotts_play.o
# target to build an object file
drivers/sensors/audiotts_play.c.o
:
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/sensors/audiotts_play.c.o
.PHONY
:
drivers/sensors/audiotts_play.c.o
drivers/sensors/audiotts_play.i
:
drivers/sensors/audiotts_play.c.i
.PHONY
:
drivers/sensors/audiotts_play.i
# target to preprocess a source file
drivers/sensors/audiotts_play.c.i
:
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/sensors/audiotts_play.c.i
.PHONY
:
drivers/sensors/audiotts_play.c.i
drivers/sensors/audiotts_play.s
:
drivers/sensors/audiotts_play.c.s
.PHONY
:
drivers/sensors/audiotts_play.s
# target to generate assembly for a file
drivers/sensors/audiotts_play.c.s
:
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/sensors/audiotts_play.c.s
.PHONY
:
drivers/sensors/audiotts_play.c.s
drivers/sensors/infrared_gun.o
:
drivers/sensors/infrared_gun.c.o
.PHONY
:
drivers/sensors/infrared_gun.o
...
...
@@ -2000,6 +2024,9 @@ help:
@
echo
"... drivers/sensors/audioplay.o"
@
echo
"... drivers/sensors/audioplay.i"
@
echo
"... drivers/sensors/audioplay.s"
@
echo
"... drivers/sensors/audiotts_play.o"
@
echo
"... drivers/sensors/audiotts_play.i"
@
echo
"... drivers/sensors/audiotts_play.s"
@
echo
"... drivers/sensors/infrared_gun.o"
@
echo
"... drivers/sensors/infrared_gun.i"
@
echo
"... drivers/sensors/infrared_gun.s"
...
...
build/main
View file @
e22b2880
No preview for this file type
build/third_party/mosquitto/CMakeFiles/progress.marks
View file @
e22b2880
7
7
7
6
build/third_party/mosquitto/apps/mosquitto_ctrl/CMakeFiles/mosquitto_ctrl.dir/progress.make
View file @
e22b2880
CMAKE_PROGRESS_1
=
CMAKE_PROGRESS_2
=
CMAKE_PROGRESS_3
=
81
CMAKE_PROGRESS_2
=
81
CMAKE_PROGRESS_3
=
CMAKE_PROGRESS_4
=
CMAKE_PROGRESS_5
=
82
CMAKE_PROGRESS_6
=
...
...
build/third_party/mosquitto/lib/CMakeFiles/libmosquitto.dir/progress.make
View file @
e22b2880
...
...
@@ -34,8 +34,8 @@ CMAKE_PROGRESS_33 =
CMAKE_PROGRESS_34
=
CMAKE_PROGRESS_35
=
12
CMAKE_PROGRESS_36
=
CMAKE_PROGRESS_37
=
13
CMAKE_PROGRESS_38
=
CMAKE_PROGRESS_37
=
CMAKE_PROGRESS_38
=
13
CMAKE_PROGRESS_39
=
CMAKE_PROGRESS_40
=
14
CMAKE_PROGRESS_41
=
...
...
build/third_party/mosquitto/lib/CMakeFiles/libmosquitto_static.dir/progress.make
View file @
e22b2880
...
...
@@ -7,8 +7,8 @@ CMAKE_PROGRESS_6 =
CMAKE_PROGRESS_7
=
CMAKE_PROGRESS_8
=
18
CMAKE_PROGRESS_9
=
CMAKE_PROGRESS_10
=
19
CMAKE_PROGRESS_11
=
CMAKE_PROGRESS_10
=
CMAKE_PROGRESS_11
=
19
CMAKE_PROGRESS_12
=
CMAKE_PROGRESS_13
=
20
CMAKE_PROGRESS_14
=
...
...
@@ -24,11 +24,11 @@ CMAKE_PROGRESS_23 =
CMAKE_PROGRESS_24
=
CMAKE_PROGRESS_25
=
24
CMAKE_PROGRESS_26
=
CMAKE_PROGRESS_27
=
25
CMAKE_PROGRESS_28
=
CMAKE_PROGRESS_27
=
CMAKE_PROGRESS_28
=
25
CMAKE_PROGRESS_29
=
CMAKE_PROGRESS_30
=
26
CMAKE_PROGRESS_31
=
CMAKE_PROGRESS_30
=
CMAKE_PROGRESS_31
=
26
CMAKE_PROGRESS_32
=
CMAKE_PROGRESS_33
=
27
CMAKE_PROGRESS_34
=
...
...
build/third_party/mosquitto/plugins/dynamic-security/CMakeFiles/mosquitto_dynamic_security.dir/progress.make
View file @
e22b2880
...
...
@@ -3,8 +3,8 @@ CMAKE_PROGRESS_2 =
CMAKE_PROGRESS_3
=
CMAKE_PROGRESS_4
=
86
CMAKE_PROGRESS_5
=
CMAKE_PROGRESS_6
=
CMAKE_PROGRESS_7
=
87
CMAKE_PROGRESS_6
=
87
CMAKE_PROGRESS_7
=
CMAKE_PROGRESS_8
=
CMAKE_PROGRESS_9
=
88
CMAKE_PROGRESS_10
=
...
...
build/third_party/mosquitto/src/CMakeFiles/mosquitto.dir/progress.make
View file @
e22b2880
CMAKE_PROGRESS_1
=
54
CMAKE_PROGRESS_1
=
CMAKE_PROGRESS_2
=
CMAKE_PROGRESS_3
=
CMAKE_PROGRESS_4
=
55
CMAKE_PROGRESS_3
=
55
CMAKE_PROGRESS_4
=
CMAKE_PROGRESS_5
=
CMAKE_PROGRESS_6
=
CMAKE_PROGRESS_7
=
56
CMAKE_PROGRESS_6
=
56
CMAKE_PROGRESS_7
=
CMAKE_PROGRESS_8
=
CMAKE_PROGRESS_9
=
57
CMAKE_PROGRESS_10
=
...
...
@@ -14,14 +14,14 @@ CMAKE_PROGRESS_13 =
CMAKE_PROGRESS_14
=
CMAKE_PROGRESS_15
=
59
CMAKE_PROGRESS_16
=
CMAKE_PROGRESS_17
=
CMAKE_PROGRESS_18
=
60
CMAKE_PROGRESS_17
=
60
CMAKE_PROGRESS_18
=
CMAKE_PROGRESS_19
=
CMAKE_PROGRESS_20
=
CMAKE_PROGRESS_21
=
61
CMAKE_PROGRESS_20
=
61
CMAKE_PROGRESS_21
=
CMAKE_PROGRESS_22
=
CMAKE_PROGRESS_23
=
CMAKE_PROGRESS_24
=
62
CMAKE_PROGRESS_23
=
62
CMAKE_PROGRESS_24
=
CMAKE_PROGRESS_25
=
CMAKE_PROGRESS_26
=
63
CMAKE_PROGRESS_27
=
...
...
@@ -34,11 +34,11 @@ CMAKE_PROGRESS_33 =
CMAKE_PROGRESS_34
=
CMAKE_PROGRESS_35
=
66
CMAKE_PROGRESS_36
=
CMAKE_PROGRESS_37
=
CMAKE_PROGRESS_38
=
67
CMAKE_PROGRESS_37
=
67
CMAKE_PROGRESS_38
=
CMAKE_PROGRESS_39
=
CMAKE_PROGRESS_40
=
CMAKE_PROGRESS_41
=
68
CMAKE_PROGRESS_40
=
68
CMAKE_PROGRESS_41
=
CMAKE_PROGRESS_42
=
CMAKE_PROGRESS_43
=
69
CMAKE_PROGRESS_44
=
...
...
@@ -54,8 +54,8 @@ CMAKE_PROGRESS_53 =
CMAKE_PROGRESS_54
=
CMAKE_PROGRESS_55
=
73
CMAKE_PROGRESS_56
=
CMAKE_PROGRESS_57
=
CMAKE_PROGRESS_58
=
74
CMAKE_PROGRESS_57
=
74
CMAKE_PROGRESS_58
=
CMAKE_PROGRESS_59
=
CMAKE_PROGRESS_60
=
75
CMAKE_PROGRESS_61
=
...
...
@@ -71,6 +71,6 @@ CMAKE_PROGRESS_70 =
CMAKE_PROGRESS_71
=
CMAKE_PROGRESS_72
=
79
CMAKE_PROGRESS_73
=
CMAKE_PROGRESS_74
=
CMAKE_PROGRESS_75
=
80
CMAKE_PROGRESS_74
=
80
CMAKE_PROGRESS_75
=
build/third_party/mosquitto/src/CMakeFiles/progress.marks
View file @
e22b2880
2
7
2
6
drivers/sensors/audioplay.c
View file @
e22b2880
...
...
@@ -108,6 +108,10 @@ void audioplay_cycle(){
}
audioplay_send_mqtt
();
}
video_tts_play
();
delay_us
(
500
);
}
}
...
...
drivers/sensors/audiotts_play.c
View file @
e22b2880
...
...
@@ -16,6 +16,8 @@ static size_t http_response_len = 0;
static
bool
audio_tts_index
=
0
;
static
double
g_volume
=
1
.
0
;
// HTTP 响应回调函数:接收服务器返回的 JSON 数据
static
size_t
http_write_callback
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
userdata
)
{
...
...
@@ -106,13 +108,58 @@ int save_audio_file(const void *data, size_t len, const char *filepath) {
return
0
;
}
/*
*功能:获得随机字符串,不使用uuid
*/
char
*
generate_random_string
()
{
// 设置随机种子(建议在main函数中调用一次即可)
static
int
seeded
=
0
;
if
(
!
seeded
)
{
srand
((
unsigned
int
)
time
(
NULL
));
seeded
=
1
;
}
// 动态分配内存(10个字符 + 终止符)
char
*
str
=
(
char
*
)
malloc
(
11
*
sizeof
(
char
));
if
(
!
str
)
return
NULL
;
// 生成数字字符(ASCII 48-57)
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
str
[
i
]
=
'0'
+
(
rand
()
%
10
);
}
str
[
10
]
=
'\0'
;
// 添加终止符
return
str
;
}
char
*
get_audio_text_tts
(
char
*
date
,
bool
flag
){
static
char
text
[
256
]
=
{
0
};
if
(
flag
==
1
){
return
text
;
}
else
{
size_t
date_len
=
strlen
(
date
);
if
(
date
)
{
strcpy
(
text
,
date
);
text
[
date_len
]
=
'\0'
;
// 确保以null结尾
}
else
{
text
[
0
]
=
'\0'
;
// 如果date为NULL,清空文本
}
}
}
/**
* 保存音频数据到文件(目录已存在)
* @param text 传入需要转化的文字指针
* @return 0成功,1失败
*/
int
audio_tts
(
const
char
*
text
)
{
// 1. 配置参数(替换为你的真实信息,已验证有效)
const
char
*
appid
=
"5745089507"
;
// 你的火山引擎 AppID
const
char
*
access_token
=
"0BeoBb_DOjrxfM4aTsJfUFVVS0k5V9mt"
;
// 你的访问令牌
const
char
*
voice_type
=
"zh_female_linjianvhai_moon_bigtts"
;
// 非流式音色
const
char
*
cluster
=
"volcano_tts"
;
// 固定值(必选)
c
onst
char
*
uid
=
"user123456"
;
// 任意非空字符串
c
har
*
uid
=
generate_random_string
()
;
// 任意非空字符串
const
char
*
encoding
=
"mp3"
;
// 输出格式(mp3/wav/pcm/ogg_opus)
const
char
*
endpoint
=
"https://openspeech.bytedance.com/api/v1/tts"
;
// HTTP 接口地址
...
...
@@ -125,6 +172,7 @@ int audio_tts(const char *text) {
cJSON
*
root
=
cJSON_CreateObject
();
if
(
!
root
)
{
my_zlog_error
(
"Create JSON root failed"
);
free
(
uid
);
return
1
;
}
...
...
@@ -165,6 +213,7 @@ int audio_tts(const char *text) {
cJSON_Delete
(
root
);
if
(
!
payload
)
{
my_zlog_error
(
"Generate JSON payload failed"
);
free
(
uid
);
return
1
;
}
my_zlog_info
(
"Request Payload: %s"
,
payload
);
...
...
@@ -175,6 +224,7 @@ int audio_tts(const char *text) {
if
(
!
curl
)
{
my_zlog_error
(
"Initialize curl failed"
);
free
(
payload
);
free
(
uid
);
return
1
;
}
...
...
@@ -186,6 +236,12 @@ int audio_tts(const char *text) {
headers
=
curl_slist_append
(
headers
,
"Content-Type: application/json"
);
headers
=
curl_slist_append
(
headers
,
"Accept: application/json"
);
if
(
http_response
==
NULL
)
{
http_response_len
=
0
;
}
else
{
return
1
;
}
// curl 核心配置
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
endpoint
);
curl_easy_setopt
(
curl
,
CURLOPT_HTTPHEADER
,
headers
);
...
...
@@ -199,10 +255,11 @@ int audio_tts(const char *text) {
curl_easy_setopt
(
curl
,
CURLOPT_CONNECTTIMEOUT
,
10L
);
// 连接超时 10 秒
// 5. 执行 HTTP 请求
printf
(
"Sending request to %s...
\n
"
,
endpoint
);
my_zlog_info
(
"Sending request to %s...
"
,
endpoint
);
CURLcode
res
=
curl_easy_perform
(
curl
);
if
(
res
!=
CURLE_OK
)
{
fprintf
(
stderr
,
"curl_easy_perform failed: %s
\n
"
,
curl_easy_strerror
(
res
));
my_zlog_error
(
"curl_easy_perform failed: %s"
,
curl_easy_strerror
(
res
));
free
(
uid
);
free
(
payload
);
curl_slist_free_all
(
headers
);
curl_easy_cleanup
(
curl
);
...
...
@@ -211,9 +268,10 @@ int audio_tts(const char *text) {
}
// 6. 解析 HTTP 响应(JSON 格式)
printf
(
"Response Length: %zu bytes
\n
"
,
http_response_len
);
my_zlog_info
(
"Response Length: %zu bytes
"
,
http_response_len
);
if
(
http_response_len
==
0
)
{
fprintf
(
stderr
,
"Empty response from server
\n
"
);
my_zlog_error
(
"Empty response from server"
);
free
(
uid
);
free
(
payload
);
curl_slist_free_all
(
headers
);
curl_easy_cleanup
(
curl
);
...
...
@@ -224,7 +282,8 @@ int audio_tts(const char *text) {
// 解析 JSON 响应
cJSON
*
response_json
=
cJSON_Parse
(
http_response
);
if
(
!
response_json
)
{
fprintf
(
stderr
,
"Parse response JSON failed: %s
\n
"
,
cJSON_GetErrorPtr
());
my_zlog_error
(
"Parse response JSON failed: %s"
,
cJSON_GetErrorPtr
());
free
(
uid
);
free
(
payload
);
free
(
http_response
);
curl_slist_free_all
(
headers
);
...
...
@@ -242,10 +301,11 @@ int audio_tts(const char *text) {
cJSON
*
code
=
cJSON_GetObjectItem
(
response_json
,
"code"
);
cJSON
*
message
=
cJSON_GetObjectItem
(
response_json
,
"message"
);
if
(
!
code
||
code
->
valueint
!=
3000
||
!
message
||
strcmp
(
message
->
valuestring
,
"Success"
)
!=
0
)
{
fprintf
(
stderr
,
"Request failed! Code: %d, Message: %s
\n
"
,
my_zlog_error
(
"Request failed! Code: %d, Message: %s
"
,
code
?
code
->
valueint
:
-
1
,
message
?
message
->
valuestring
:
"No message"
);
cJSON_Delete
(
response_json
);
free
(
uid
);
free
(
payload
);
free
(
http_response
);
curl_slist_free_all
(
headers
);
...
...
@@ -253,13 +313,14 @@ int audio_tts(const char *text) {
curl_global_cleanup
();
return
1
;
}
printf
(
"Request succeeded! Code: %d, Message: %s
\n
"
,
code
->
valueint
,
message
->
valuestring
);
my_zlog_info
(
"Request succeeded! Code: %d, Message: %s
"
,
code
->
valueint
,
message
->
valuestring
);
// 关键:直接提取 data 字段的 Base64 音频字符串(接口实际返回格式)
cJSON
*
audio_base64
=
cJSON_GetObjectItem
(
response_json
,
"data"
);
if
(
!
audio_base64
||
!
audio_base64
->
valuestring
||
strlen
(
audio_base64
->
valuestring
)
==
0
)
{
fprintf
(
stderr
,
"Response missing audio data (data field is empty)
\n
"
);
my_zlog_error
(
"Response missing audio data (data field is empty)
"
);
cJSON_Delete
(
response_json
);
free
(
uid
);
free
(
payload
);
free
(
http_response
);
curl_slist_free_all
(
headers
);
...
...
@@ -267,7 +328,7 @@ int audio_tts(const char *text) {
curl_global_cleanup
();
return
1
;
}
my_zlog_info
(
"Audio Base64 Length: %zu bytes
\n
"
,
strlen
(
audio_base64
->
valuestring
));
my_zlog_info
(
"Audio Base64 Length: %zu bytes"
,
strlen
(
audio_base64
->
valuestring
));
// 7. Base64 解码音频数据
size_t
audio_len
=
0
;
...
...
@@ -275,6 +336,7 @@ int audio_tts(const char *text) {
if
(
!
audio_data
||
audio_len
==
0
)
{
my_zlog_error
(
"Base64 decode audio failed"
);
cJSON_Delete
(
response_json
);
free
(
uid
);
free
(
payload
);
free
(
http_response
);
curl_slist_free_all
(
headers
);
...
...
@@ -290,6 +352,7 @@ int audio_tts(const char *text) {
// 9. 清理资源(避免内存泄漏)
cJSON_Delete
(
response_json
);
free
(
uid
);
free
(
audio_data
);
free
(
payload
);
free
(
http_response
);
...
...
@@ -297,13 +360,123 @@ int audio_tts(const char *text) {
curl_easy_cleanup
(
curl
);
curl_global_cleanup
();
// 初始化响应缓冲
http_response
=
NULL
;
http_response_len
=
0
;
return
0
;
}
/*
*功能: 设置播放标识
*/
void
set_audio_tts_index
(
bool
index
){
audio_tts_index
=
index
;
}
bool
get_audio_tts_index
(){
return
audio_tts_index
;
/*
*功能: 发送mqtt
*/
int
mqtt_audio_tts_send
(
int
status
){
// 创建根对象
cJSON
*
root
=
cJSON_CreateObject
();
if
(
root
==
NULL
)
{
return
1
;
}
// 创建body对象
cJSON
*
body
=
cJSON_CreateObject
();
if
(
body
==
NULL
)
{
cJSON_Delete
(
root
);
return
1
;
}
cJSON
*
head
=
cJSON_CreateObject
();
if
(
head
==
NULL
)
{
cJSON_Delete
(
root
);
return
1
;
}
// 将body添加到root
cJSON_AddItemToObject
(
root
,
"body"
,
body
);
// 添加type和status字段到body
cJSON_AddStringToObject
(
body
,
"type"
,
"tts_audio"
);
cJSON_AddNumberToObject
(
body
,
"status"
,
status
);
cJSON_AddNumberToObject
(
head
,
"message_type"
,
3020
);
cJSON_AddItemToObject
(
root
,
"body"
,
body
);
cJSON_AddItemToObject
(
root
,
"head"
,
head
);
// 生成JSON字符串
char
*
json_str
=
cJSON_PrintUnformatted
(
root
);
my_zlog_debug
(
"%s"
,
json_str
);
for
(
int
i
=
0
;
i
<
g_mqtt_cam_config_t
->
mqtt_count
;
i
++
){
mosquitto_publish
(
g_clients_t
[
i
].
mosq
,
NULL
,
mqtt_topic_pure_number
(),
strlen
(
json_str
),
json_str
,
0
,
false
);
}
// 释放 JSON 对象内存
cJSON_Delete
(
root
);
return
0
;
}
int
mqtt_audio_tts
(
cJSON
*
body
){
// 解析type字段
cJSON
*
type
=
cJSON_GetObjectItem
(
body
,
"type"
);
if
(
type
==
NULL
||
strcmp
(
type
->
valuestring
,
"tts_audio"
)
!=
0
){
my_zlog_error
(
"type is tts_audio error"
);
return
1
;
}
// 解析date字段
cJSON
*
date
=
cJSON_GetObjectItem
(
body
,
"date"
);
if
(
date
!=
NULL
){
get_audio_text_tts
(
date
->
valuestring
,
0
);
my_zlog_info
(
"text:%s"
,
date
->
valuestring
);
}
else
{
return
1
;
}
// 解析status字段
cJSON
*
status
=
cJSON_GetObjectItem
(
body
,
"status"
);
if
(
mqtt_audio_tts_send
(
status
->
valueint
)
==
0
){
set_audio_tts_index
(
status
->
valueint
);
}
else
{
set_audio_tts_index
(
0
);
my_zlog_error
(
"statis error"
);
return
1
;
}
cJSON
*
volume
=
cJSON_GetObjectItem
(
body
,
"volume"
);
g_volume
=
volume
->
valuedouble
;
return
0
;
}
/*
*功能,tts播放
*/
void
video_tts_play
(){
if
(
audio_tts_index
==
1
)
{
audio_tts
(
get_audio_text_tts
(
NULL
,
1
));
char
command
[
256
];
snprintf
(
command
,
sizeof
(
command
),
"ffmpeg -i /home/orangepi/car/master/audio.mp3 -af
\"
volume=%.1f
\"
-f alsa default"
,
g_volume
);
int
res
=
system
(
command
);
if
(
res
==
0
)
my_zlog_info
(
"play success, volume: %.1f"
,
g_volume
);
else
my_zlog_error
(
"system play fail, volume: %.1f"
,
g_volume
);
audio_tts_index
==
0
;
}
}
\ No newline at end of file
drivers/sensors/audiotts_play.h
View file @
e22b2880
...
...
@@ -3,8 +3,14 @@
#include "common.h"
void
set_audio_tts_index
(
bool
index
);
/*
*将接收到的保存到指定文件
*/
int
mqtt_audio_tts
(
cJSON
*
body
);
int
audio_tts
(
const
char
*
text
);
/*
*功能,tts播放
*/
void
video_tts_play
();
bool
get_audio_tts_index
();
#endif
\ No newline at end of file
modules/mqtt/mqtt_infor_handle.c
View file @
e22b2880
...
...
@@ -337,7 +337,10 @@ int device_message_receive(cJSON *json){//接收到的控制设备的mqtt消息
break
;
case
2026
:
receive_self_contorl_date_mqtt
(
body
);
my_zlog_debug
(
"device self comtrol date save"
);
my_zlog_info
(
"device self comtrol date save"
);
case
2027
:
mqtt_audio_tts
(
body
);
my_zlog_info
(
"device audio_tts"
);
default
:
break
;
}
...
...
modules/mqtt/mqtt_init.c
View file @
e22b2880
...
...
@@ -244,35 +244,29 @@ void mqtt_clean(){
int
mqtt_cycle
()
{
//非阻塞型
my_zlog_info
(
"MQTT 异步监控线程启动"
);
int
check_interval
=
30000
;
// 30秒检查一次,减少日志频率
while
(
1
)
{
// bool all_connected = true;
// for (int i = 0; i < g_mqtt_cam_config_t->mqtt_count; i++) {
// if (!g_clients_t[i].mosq) continue;
// int state = mosquitto_socket(g_clients_t[i].mosq);
// if (state == -1) {
// all_connected = false;
// my_zlog_warn("检测到 MQTT [%s:%d] 已断开,尝试重连...",
// g_clients_t[i].host, g_clients_t[i].port);
// //mosquitto_reconnect_async(g_clients_t[i].mosq);
// }
// }
delay_ms
(
1000
);
// 每 1 秒检测一次连接状态
// 简单的存活检查,记录连接状态
int
active_count
=
0
;
int
total_count
=
g_mqtt_cam_config_t
?
g_mqtt_cam_config_t
->
mqtt_count
:
0
;
for
(
int
i
=
0
;
i
<
total_count
;
i
++
)
{
if
(
g_clients_t
[
i
].
mosq
&&
!
g_clients_t
[
i
].
permanently_failed
)
{
active_count
++
;
}
}
// 只在状态变化或定期记录
static
int
last_active_count
=
-
1
;
if
(
active_count
!=
last_active_count
)
{
my_zlog_info
(
"MQTT 连接状态: %d/%d 活跃"
,
active_count
,
total_count
);
last_active_count
=
active_count
;
}
delay_ms
(
check_interval
);
}
// while (1) {
// for(int i=0;i<g_mqtt_cam_config_t->mqtt_count;i++){
// int rc= mosquitto_loop(g_clients_t[i].mosq, 17, 1); // 每秒检查一次
// if(rc != MOSQ_ERR_SUCCESS){
// my_zlog_warn("服务器 %s:%d 断开,尝试重连...",
// g_clients_t[i].host, g_clients_t[i].port);
// mosquitto_reconnect(g_clients_t[i].mosq);
// }
// }
// delay_us(50);
// }
return
0
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment