@@ -97,36 +97,38 @@ def test_deprecated_prepare(self):
97
97
api .prepare (self .data_dir / "ej-fra.txt" , os .devnull , ("fra" ,))
98
98
self .assertIn ("deprecated" , "\n " .join (cm .output ))
99
99
100
+ sentences_to_convert = [
101
+ [
102
+ api .Token ("Bonjöûr," , 0.2 , 1.0 ),
103
+ api .Token (" " ),
104
+ api .Token ("hello" , 1.0 , 0.2 ),
105
+ api .Token ("!" ),
106
+ ],
107
+ [api .Token ("Sentence2" , 4.2 , 0.2 ), api .Token ("!" )],
108
+ [],
109
+ [api .Token ("Paragraph2" , 4.2 , 0.2 ), api .Token ("." )],
110
+ [],
111
+ [],
112
+ [
113
+ api .Token ("(" ),
114
+ api .Token ('"' ),
115
+ api .Token ("Page2" , 5.2 , 0.2 ),
116
+ api .Token ("." ),
117
+ api .Token ('"' ),
118
+ api .Token (")" ),
119
+ ],
120
+ ]
121
+
100
122
def test_convert_to_readalong (self ):
101
- sentences = [
102
- [
103
- api .Token ("Bonjöûr," , 0.2 , 1.0 ),
104
- api .Token (" " ),
105
- api .Token ("hello" , 1.0 , 0.2 ),
106
- api .Token ("!" ),
107
- ],
108
- [api .Token ("Sentence2" , 4.2 , 0.2 ), api .Token ("!" )],
109
- [],
110
- [api .Token ("Paragraph2" , 4.2 , 0.2 ), api .Token ("." )],
111
- [],
112
- [],
113
- [
114
- api .Token ("(" ),
115
- api .Token ('"' ),
116
- api .Token ("Page2" , 5.2 , 0.2 ),
117
- api .Token ("." ),
118
- api .Token ('"' ),
119
- api .Token (")" ),
120
- ],
121
- ]
122
-
123
- readalong = api .convert_to_readalong (sentences )
123
+
124
+ readalong = api .convert_to_readalong (self .sentences_to_convert )
124
125
# print(readalong)
125
126
126
127
# Make the reference by calling align with the same text and adjusting
127
128
# things we expect to be different.
128
129
sentences_as_text = "\n " .join (
129
- "" .join (token .text for token in sentence ) for sentence in sentences
130
+ "" .join (token .text for token in sentence )
131
+ for sentence in self .sentences_to_convert
130
132
)
131
133
with open (self .tempdir / "sentences.txt" , "w" , encoding = "utf8" ) as f :
132
134
f .write (sentences_as_text )
@@ -152,6 +154,21 @@ def test_convert_to_readalong(self):
152
154
readalong = re .sub (r"dur=\".*?\"" , 'dur="ddd"' , readalong )
153
155
self .assertEqual (readalong , align_result )
154
156
157
+ def test_convert_to_offline_html (self ):
158
+ html = api .convert_to_offline_html (
159
+ self .sentences_to_convert , str (self .data_dir / "noise.mp3" )
160
+ )
161
+ with open ("test.html" , "w" , encoding = "utf8" ) as f :
162
+ f .write (html )
163
+ # print(html)
164
+ self .assertIn ("<html" , html )
165
+ self .assertIn ("<body" , html )
166
+ self .assertIn ('<meta name="generator" content="@readalongs/studio (cli)' , html )
167
+ self .assertIn ('<read-along href="data:application/readalong+xml;base64' , html )
168
+ self .assertIn ('audio="data:audio/' , html )
169
+ self .assertIn ("<span slot='read-along-header'>" , html )
170
+ self .assertIn ("<span slot='read-along-subheader'>" , html )
171
+
155
172
156
173
if __name__ == "__main__" :
157
174
main ()
0 commit comments