fakeyou_api/apis/
voice.rs1use crate::{ApiResult, Error, FakeYou};
7use reqwest::StatusCode;
8use serde::{Deserialize, Serialize};
9
10use super::TTS_VOICES;
11
12#[derive(Debug, Serialize, Deserialize)]
13pub struct TtsListResult {
14 pub success: bool,
16 pub models: Vec<TtsModel>,
18}
19
20#[derive(Debug, Serialize, Deserialize)]
21pub struct TtsModel {
22 pub model_token: String,
24 pub tts_model_type: String,
26 pub creator_user_token: String,
28 pub creator_username: String,
30 pub creator_display_name: String,
32 pub creator_gravatar_hash: String,
34 pub title: String,
36 pub ietf_language_tag: String,
38 pub ietf_primary_language_subtag: String,
40 pub is_front_page_featured: bool,
42 pub is_twitch_featured: bool,
44 pub maybe_suggested_unique_bot_command: Option<String>,
46 pub category_tokens: Vec<String>,
48 pub created_at: String,
50 pub updated_at: String,
52}
53
54pub trait VoicesApi {
55 fn tts_voices(&self) -> ApiResult<TtsListResult>;
56}
57
58impl VoicesApi for FakeYou {
59 fn tts_voices(&self) -> ApiResult<TtsListResult> {
60 let url = format!("{}/{}", &self.api_url, TTS_VOICES);
61
62 let response = self
63 .client
64 .get(url.as_str())
65 .header("Accept", "application/json")
66 .send()
67 .map_err(|e| Error::RequestFailed(e.to_string()))?;
68
69 match response.status() {
70 StatusCode::OK => response
71 .json::<TtsListResult>()
72 .map_err(|e| Error::ParseError(e.to_string())),
73 code => Err(Error::Unknown(code.as_u16())),
74 }
75 }
76}