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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use serde::{Deserialize, Serialize};
/// A NOAA Weather Radio broadcast in SSML (Speech Synthesis Markup Language) format.
///
/// Represents the root `<speak>` element of the SSML document returned by
/// the `/radio/{callSign}/broadcast` and `/points/{point}/radio` endpoints.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename = "speak")]
pub struct RadioBroadcast {
/// SSML specification version (e.g., "1.1").
#[serde(rename = "@version")]
pub version: String,
/// Language of the broadcast (e.g., "en-US").
#[serde(rename = "@xml:lang")]
pub lang: String,
/// Broadcast paragraphs containing sentences and metadata marks.
#[serde(rename = "p", default)]
pub paragraphs: Vec<Paragraph>,
}
/// A paragraph within the broadcast, corresponding to a `<p>` SSML element.
///
/// Contains one or more sentences and optional metadata marks.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Paragraph {
/// Sentences within this paragraph.
#[serde(rename = "s", default)]
pub sentences: Vec<Sentence>,
/// Metadata marks embedded in this paragraph (e.g., station ID, frequency).
#[serde(rename = "mark", default)]
pub marks: Vec<BroadcastMark>,
}
/// A sentence within a broadcast paragraph, corresponding to an `<s>` SSML element.
///
/// Sentences may contain plain text, `<say-as>` pronunciation hints, or a mix of both.
/// The `content` field preserves the ordering of text and inline elements.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Sentence {
/// Ordered sequence of text fragments and inline SSML elements.
#[serde(rename = "$value", default)]
pub content: Vec<SentenceContent>,
}
impl Sentence {
/// Returns the full text of the sentence, concatenating all text fragments
/// and the text content of any `<say-as>` elements.
pub fn full_text(&self) -> String {
self.content
.iter()
.map(|part| match part {
SentenceContent::Text(t) => t.as_str(),
SentenceContent::SayAs(sa) => sa.text.as_str(),
})
.collect()
}
}
/// A content fragment within a [`Sentence`].
///
/// Represents either a plain text node or an inline `<say-as>` element
/// that provides pronunciation guidance for text-to-speech engines.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum SentenceContent {
/// A plain text fragment.
#[serde(rename = "$text")]
Text(String),
/// A `<say-as>` element providing pronunciation interpretation.
#[serde(rename = "say-as")]
SayAs(SayAs),
}
/// An SSML `<say-as>` element that tells a speech synthesizer how to interpret text.
///
/// For example, `<say-as interpret-as="characters">KEC94</say-as>` instructs the
/// synthesizer to spell out each character individually.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct SayAs {
/// Interpretation hint (e.g., "characters", "date", "telephone").
#[serde(rename = "@interpret-as")]
pub interpret_as: String,
/// The text content to be interpreted.
#[serde(rename = "$text")]
pub text: String,
}
/// An SSML `<mark>` element carrying broadcast metadata as a JSON-like string.
///
/// The `name` attribute typically contains a Python-style dictionary string
/// with keys such as `requesterSameCode`, `transmitter`, `stationId`, and
/// `sameLocations`.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct BroadcastMark {
/// Metadata payload as a string (often a Python-style dict literal).
#[serde(rename = "@name")]
pub name: String,
}