12
12
13
13
14
14
class ForecastParser (HTMLParser ):
15
- _text = "" ;
15
+ _text = ""
16
16
_lastTag = ""
17
17
18
18
def __init__ (self ):
19
19
super ().__init__ ()
20
20
pass
21
21
22
22
def handle_starttag (self , tag , attrs ):
23
- self ._lastTag = tag ;
23
+ self ._lastTag = tag
24
24
25
25
def handle_endtag (self , tag ):
26
26
if self ._lastTag == "strong" :
27
27
self ._text += '<break time="0.4s"/>'
28
28
29
- self ._lastTag = "" ;
29
+ self ._lastTag = ""
30
30
31
31
32
32
def handle_data (self , data ):
33
33
if not data :
34
- return ;
34
+ return
35
35
36
36
if not self ._lastTag :
37
- return ;
37
+ return
38
38
39
- self ._text += data ;
39
+ self ._text += data
40
40
41
41
42
42
def clear (self ):
@@ -88,7 +88,7 @@ def fetch_text(self, url):
88
88
lines = parser ._text .splitlines ()
89
89
90
90
# Meta zeugs rausfiltern
91
- newLines = [];
91
+ newLines = []
92
92
for line in lines :
93
93
line = line .strip ()
94
94
@@ -151,21 +151,20 @@ def fetch_text(self, url):
151
151
152
152
newLines .append (line )
153
153
154
- return newLines ;
154
+ return newLines
155
155
156
156
def fetch (self ) -> str :
157
- parser = ForecastParser ()
157
+ # parser = ForecastParser()
158
158
159
- allLines = [];
159
+ allLines = []
160
160
allLines .append ("<speak>\r \n " )
161
161
162
162
# Gesamtwetterlage
163
163
allLines .append ('\r \n <!-- Gesamtwetterlage -->\r \n ' )
164
164
allLines .append ("<p>\r \n " )
165
165
166
- lines = self .fetch_text ('http://opendata.dwd.de/weather/text_forecasts/html/VHDL54_DW{0}_LATEST_html' .format (self ._stateKey ));
166
+ lines = self .fetch_text ('http://opendata.dwd.de/weather/text_forecasts/html/VHDL54_DW{0}_LATEST_html' .format (self ._stateKey ))
167
167
168
- # allLines.append('Die Wetterlage:<break time="0.5s"/>\r\n')
169
168
for line in lines :
170
169
allLines .append (line + "\r \n " )
171
170
@@ -188,7 +187,7 @@ def fetch(self) -> str:
188
187
allLines .append ('<break time="1.2s"/>\r \n <p>\r \n ' )
189
188
allLines .append ('<s>Die Aussichten für morgen.</s><break time="0.4s"/>\r \n ' )
190
189
191
- lines = self .fetch_text ('http://opendata.dwd.de/weather/text_forecasts/html/VHDL51_DW{0}_LATEST_html' .format (self ._stateKey ));
190
+ lines = self .fetch_text ('http://opendata.dwd.de/weather/text_forecasts/html/VHDL51_DW{0}_LATEST_html' .format (self ._stateKey ))
192
191
for line in lines :
193
192
allLines .append (line + "\r \n " )
194
193
@@ -198,14 +197,14 @@ def fetch(self) -> str:
198
197
199
198
s = ""
200
199
for line in allLines :
201
- s += line ;
200
+ s += line
202
201
203
202
return s
204
203
205
204
206
205
class TextToSpeech :
207
206
_keyFile = ""
208
- _useWaveNet = True ;
207
+ _useWaveNet = True
209
208
210
209
def __init__ (self , keyfile : str , useWaveNet : bool ):
211
210
self ._keyFile = keyfile
@@ -252,6 +251,7 @@ def main():
252
251
parser .add_argument ("-o" , "--Output" , dest = "output" ,help = 'Name der Ausgabedatei' , type = str , required = False , default = 'output.mp3' )
253
252
parser .add_argument ("-s" , "--State" , dest = "state" ,help = 'Bundesland' , default = 'Sachsen' , choices = [u'Sachsen' , u'Sachsen-Anhalt' , u'Thüringen' , u'Berlin' , u'Mecklenburg-Vorpomern' , u'Brandenburg' , u'Niedersachsen' , u'Bremen' , u'Hamburg' , u'Rheinland-Pfalz' , u'Bayern' , u'Hessen' , u'Saarland' , u'Baden-Würtenberg' , u'Schleswig-Holstein' , u'Nordrhein-Westfalen' ])
254
253
parser .add_argument ("-k" , "--Keyfile" , dest = "key_file" , help = 'Pfad zu der json Datei mit dem Key für das google text-to-speech api' , required = True )
254
+ parser .add_argument ("-t" , "--TextOnly" , dest = "text_only" , help = 'Wenn dieses Flag gesetzt ist wird nur eine ssml datei erstellt.' , required = False , default = False , action = 'store_true' )
255
255
parser .add_argument ("-wave" , "--UseWaveNet" , dest = "use_wave_net" , help = 'Wenn dieses flag gesetzt ist wird sprache hoher qualität ausgegeben.' , required = False , default = False , action = 'store_true' )
256
256
parser .add_argument ("-nowarn" , "--NoWarnings" , dest = "skip_warnings" , help = 'Ignoriere die Abschnitte zu Warnrelevanten Wettermeldungen.' , required = False , default = False , action = 'store_true' )
257
257
@@ -287,10 +287,14 @@ def main():
287
287
print ('------------------------------------------' )
288
288
print (ssml )
289
289
290
-
291
- print ('\r \n Erzeuge Sprachversion...' )
292
- tts = TextToSpeech (args .key_file , args .use_wave_net )
293
- tts .text_to_speech (ssml , args .output );
290
+ if (args .text_only ):
291
+ text_filename = os .path .splitext (args .output )[0 ] + '.ssml'
292
+ with open (text_filename , 'w' ) as f :
293
+ f .write (ssml )
294
+ else :
295
+ print ('\r \n Erzeuge Sprachversion...' )
296
+ tts = TextToSpeech (args .key_file , args .use_wave_net )
297
+ tts .text_to_speech (ssml , args .output );
294
298
295
299
# Prerequisites:
296
300
# sudo apt-get install python3-setuptools
0 commit comments