1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use arci::WaitFuture;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

mod msg {
    rosrust::rosmsg_include!(std_msgs / String);
}

pub struct RosEspeakClient {
    publisher: rosrust::Publisher<msg::std_msgs::String>,
}

#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct RosEspeakClientConfig {
    pub topic: String,
}

impl RosEspeakClient {
    pub fn new(topic: &str) -> Self {
        Self {
            publisher: rosrust::publish(topic, 2).unwrap(),
        }
    }
}

impl arci::Speaker for RosEspeakClient {
    fn speak(&self, message: &str) -> Result<WaitFuture, arci::Error> {
        let ros_msg = msg::std_msgs::String {
            data: message.to_string(),
        };
        self.publisher
            .send(ros_msg)
            .map_err(|e| anyhow::format_err!("{e}"))?;
        Ok(WaitFuture::ready())
    }
}