fakeyou_api/apis/
voice.rs

1// Gets a list of available voices to use with the TTS API.
2// see: https://docs.fakeyou.com/
3
4//! Voices API
5
6use 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    /// Whether the request succeeded.
15    pub success: bool,
16    /// The tts models
17    pub models: Vec<TtsModel>,
18}
19
20#[derive(Debug, Serialize, Deserialize)]
21pub struct TtsModel {
22    /// The primary token identifier for the model.
23    pub model_token: String,
24    /// The type of synthesizer (options: tacotron2, glowtts, etc.)
25    pub tts_model_type: String,
26    /// The primary token identifier of the user that created the model
27    pub creator_user_token: String,
28    /// The username of the creator (always lowercase)
29    pub creator_username: String,
30    /// The display name of the creator (mixed case)
31    pub creator_display_name: String,
32    /// Gravatar.com hash for the user (if available)
33    pub creator_gravatar_hash: String,
34    /// Name of the model.
35    pub title: String,
36    /// IETF BCP 47 language tag.
37    pub ietf_language_tag: String,
38    /// The primary language tag of the model's speaker / dataset.
39    pub ietf_primary_language_subtag: String,
40    /// Whether the voice is highlighted on FakeYou.com
41    pub is_front_page_featured: bool,
42    /// Whether the voice is highlighted on Twitch.
43    pub is_twitch_featured: bool,
44    /// This is an optional, but guaranteed unique identifier for the voice.
45    pub maybe_suggested_unique_bot_command: Option<String>,
46    /// Categories this voice belongs to
47    pub category_tokens: Vec<String>,
48    /// Model upload date
49    pub created_at: String,
50    /// Model last edit date
51    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}