This commit is contained in:
AviiNL
2023-12-23 09:54:55 +01:00
parent 945cf75242
commit 5beec8d9b9
13 changed files with 69 additions and 47 deletions

View File

@@ -16,6 +16,7 @@ serde.workspace = true
serde_json.workspace = true
shlex.workspace = true
tokio.workspace = true
tracing.workspace = true
async-compat = "0.2.1"
serde_repr = "0.1"
crossbeam-channel = "0.5.9"

View File

@@ -20,6 +20,7 @@ use dcs_grpc::dcs::{
StreamUnitsRequest,
},
};
use tracing::{debug, info, warn};
#[derive(Clone)]
enum Response {
@@ -52,11 +53,11 @@ fn connect_to_grpc(mut commands: Commands, tokio: Res<TokioResource>, url: Res<G
handle.spawn(async move {
loop {
let Ok(mut client) = MissionServiceClient::connect(url.clone()).await else {
eprintln!("Connection failed: {}", url);
warn!("Connection failed: {}", url); // warn
tokio::time::sleep(Duration::from_secs(5)).await;
continue;
};
println!("Connected to DCS: {}", url);
info!("Connected to DCS: {}", url);
let Ok(mut stream) = client
.stream_units(StreamUnitsRequest {
@@ -77,17 +78,16 @@ fn connect_to_grpc(mut commands: Commands, tokio: Res<TokioResource>, url: Res<G
}
}
Ok(None) => {
// eprintln!("Empty?");
break;
}
Err(e) => {
eprintln!("Error from gRPC: {:?}", e);
debug!("Error from gRPC: {:?}", e); // verbose or debug log
break;
}
}
}
eprintln!("Disconnected from DCS: {}", url);
warn!("Disconnected from DCS: {}", url); // warn
tx.send(Response::Disconnected).ok();
}
});

View File

@@ -19,6 +19,7 @@ use dcs_grpc::dcs::{
common::v0::Coalition,
net::v0::{net_service_client::NetServiceClient, SendChatRequest},
};
use tracing::info;
use crate::{components::GrpcBaseUrl, TokioResource};
@@ -57,7 +58,7 @@ fn send_text_message(
// target_player_id: player_id,
};
println!("> {}", message);
info!("> {}", message);
client.send_chat(request).await.ok();
});

View File

@@ -8,6 +8,7 @@ mod voice_command;
use guardian_commands::{call::parse_call, ConsoleCommandEntered, ConsoleConfiguration};
use serde::{Deserialize, Serialize};
use simsearch::SimSearch;
use tracing::{error, info, warn};
pub use voice_command::VoiceCommand;
use crossbeam_channel::Receiver;
@@ -166,7 +167,7 @@ fn listen_srs(
radio.handle = Some(tokio.0.spawn(async move {
loop {
let Ok(tcp) = TcpStream::connect(addr).await else {
eprintln!("Connection failed: {}", addr);
warn!("Connection failed: {}", addr);
sleep(Duration::from_secs(5)).await;
continue;
};
@@ -188,7 +189,7 @@ fn listen_srs(
client: client.clone(),
version: SRS_VERSION.to_string(),
})).await {
eprintln!("Srs error: {:?}", e);
error!("Srs error: {:?}", e);
sleep(Duration::from_secs(5)).await;
continue;
};
@@ -246,7 +247,7 @@ fn listen_srs(
Ok(data) => {
match &data {
Message::VersionMismatch(VersionMismatchMessage { version, .. }) => {
eprintln!("Version mismatch {} != {}", SRS_VERSION, version);
error!("Version mismatch {} != {}", SRS_VERSION, version);
},
Message::Sync(SyncMessage { clients, .. }) => {
for client in clients.iter() {
@@ -324,7 +325,7 @@ fn listen_srs(
}
};
}
eprintln!("Disconnected from SRS: {}", addr);
warn!("Disconnected from SRS: {}", addr);
}
#[allow(unreachable_code)]
Ok(())
@@ -495,7 +496,10 @@ fn handle_voice_command(
continue;
};
println!("< {}\n\t{}", rawr.clone(), cmd.clone());
let raw = rawr.trim().to_string();
info!("Received: {}", raw);
info!("Interpreted as: {}", cmd);
let Ok((_, call)) = parse_call(cmd) else {
// no command, casual conversations?
@@ -505,9 +509,6 @@ fn handle_voice_command(
let cmd = call.command;
if config.commands.get(&cmd).is_some() {
let raw = rawr.clone();
let raw = raw.trim().to_string();
command_entered.send(ConsoleCommandEntered {
command_name: cmd.clone(),
raw,

View File

@@ -3,6 +3,7 @@
use std::borrow::Cow;
use tokio::sync::Mutex;
use tracing::{debug, error, warn};
use windows::core::HSTRING;
use windows::Media::SpeechSynthesis::SpeechSynthesizer;
use windows::Storage::Streams::DataReader;
@@ -58,21 +59,21 @@ pub async fn synthesize(text: &str, voice: &Voice) -> Result<Vec<Vec<u8>>, WinEr
let lang = v.Language()?.to_string();
if lang.starts_with("en-") {
let name = v.DisplayName()?.to_string();
println!("Using WIN voice: {}", name);
debug!("Using WIN voice: {}", name);
voice_info = Some(v);
break;
}
}
if voice_info.is_none() {
println!("Could not find any english Windows TTS voice");
error!("Could not find any english Windows TTS voice");
}
}
if voice_info.is_none() {
let all_voices = SpeechSynthesizer::AllVoices()?;
let len = all_voices.Size()? as usize;
println!(
warn!(
"Available WIN voices are (you don't have to include the `Microsoft` prefix in \
the name):"
);
@@ -84,7 +85,7 @@ pub async fn synthesize(text: &str, voice: &Voice) -> Result<Vec<Vec<u8>>, WinEr
}
let name = v.DisplayName()?.to_string();
println!("- {} ({})", name, lang);
warn!("- {} ({})", name, lang);
}
}