Commit 714bd504 authored by 957dd's avatar 957dd

加入了audio的tts

parent e22b2880
No preview for this file type
No preview for this file type
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment