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
714bd504
Commit
714bd504
authored
Nov 11, 2025
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入了audio的tts
parent
e22b2880
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
14 deletions
+66
-14
audio.mp3
audio.mp3
+0
-0
main
build/main
+0
-0
audiotts_play.c
drivers/sensors/audiotts_play.c
+66
-14
No files found.
audio.mp3
View file @
714bd504
No preview for this file type
build/main
View file @
714bd504
No preview for this file type
drivers/sensors/audiotts_play.c
View file @
714bd504
...
...
@@ -7,6 +7,10 @@
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <openssl/buffer.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#define TTS_ADUINO_PTAH "/home/orangepi/car/master/audio.mp3"
...
...
@@ -461,22 +465,69 @@ int mqtt_audio_tts(cJSON *body){
/*
*功能,tts播放
*/
void
video_tts_play
(){
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
);
audio_tts
(
get_audio_text_tts
(
NULL
,
1
));
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
;
pid_t
pid
=
fork
();
if
(
pid
==
0
)
{
// 子进程:创建新的会话组,脱离父进程组
setsid
();
// 关键!创建新的会话组
char
command
[
256
];
snprintf
(
command
,
sizeof
(
command
),
"ffmpeg -i /home/orangepi/car/master/audio.mp3 -af
\"
volume=%.1f
\"
-f alsa default 2>/dev/null"
,
g_volume
);
// 重定向标准输入输出,避免占用终端
if
(
freopen
(
"/dev/null"
,
"r"
,
stdin
)
==
NULL
)
{
my_zlog_error
(
"重定向stdin失败: %s"
,
strerror
(
errno
));
// 可以选择退出或继续
}
if
(
freopen
(
"/dev/null"
,
"w"
,
stdout
)
==
NULL
)
{
my_zlog_error
(
"重定向stdout失败: %s"
,
strerror
(
errno
));
}
if
(
freopen
(
"/dev/null"
,
"w"
,
stderr
)
==
NULL
)
{
my_zlog_error
(
"重定向stderr失败: %s"
,
strerror
(
errno
));
}
int
res
=
system
(
command
);
_exit
(
res
);
// 使用_exit避免清理父进程资源
}
else
if
(
pid
>
0
)
{
// 父进程:非阻塞等待,避免僵尸进程
int
status
;
waitpid
(
pid
,
&
status
,
WNOHANG
);
// 不阻塞的等待
my_zlog_info
(
"启动独立播放进程 PID: %d"
,
pid
);
audio_tts_index
=
0
;
}
else
{
my_zlog_error
(
"fork()失败"
);
audio_tts_index
=
0
;
}
}
}
// 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
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