Tts added
This commit is contained in:
+4
-12
@@ -2,8 +2,7 @@ use anyhow::{anyhow, Context, Result};
|
||||
use rodio::{Decoder, OutputStream, Sink};
|
||||
use std::io::Cursor;
|
||||
use std::process::{Child, Command};
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
pub struct TtsEngine {
|
||||
process: Arc<Mutex<Option<Child>>>,
|
||||
@@ -17,7 +16,6 @@ impl TtsEngine {
|
||||
let server_url = format!("http://127.0.0.1:{}", port);
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
// Check if server is already running
|
||||
let already_running = client
|
||||
.get(&format!("{}/", server_url))
|
||||
.send()
|
||||
@@ -82,7 +80,6 @@ impl TtsEngine {
|
||||
|
||||
let wav_bytes = response.bytes().await?;
|
||||
|
||||
// Play audio in a blocking thread (rodio requires sync)
|
||||
let bytes = wav_bytes.to_vec();
|
||||
std::thread::spawn(move || {
|
||||
if let Ok((_stream, stream_handle)) = OutputStream::try_default() {
|
||||
@@ -98,8 +95,8 @@ impl TtsEngine {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn stop(&self) {
|
||||
if let Ok(mut guard) = self.process.lock().await {
|
||||
pub fn stop(&self) {
|
||||
if let Ok(mut guard) = self.process.lock() {
|
||||
if let Some(ref mut child) = *guard {
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
@@ -118,11 +115,6 @@ impl TtsEngine {
|
||||
|
||||
impl Drop for TtsEngine {
|
||||
fn drop(&mut self) {
|
||||
if let Ok(mut guard) = self.process.lock() {
|
||||
if let Some(ref mut child) = *guard {
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
}
|
||||
}
|
||||
self.stop();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user