-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprebuildtime.py
83 lines (68 loc) · 1.87 KB
/
prebuildtime.py
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
import datetime
import os
import json
import logging
from google.cloud import texttospeech
def wrap_in_p(lines):
return ["<p>{}</p>".format(l) for l in lines]
def hodiny(n):
if n == 1:
return f"jedna hodina"
if n == 2:
return f"dve hodiny"
elif n in (
3,
4,
):
return f"{n} hodiny"
else:
return f"{n} hodín"
def minuty(n):
if n == 1:
return f"jedna minúta"
if n == 2:
return f"dve minúty"
elif n in (
3,
4,
):
return f"{n} minúty"
else:
return f"{n} minút"
def gen_time(hours, minutes):
logging.info("Calling google API")
try:
client = texttospeech.TextToSpeechClient()
voice = texttospeech.VoiceSelectionParams(
language_code="sk-SK",
name="sk-SK-Wavenet-A",
)
audio_config = texttospeech.AudioConfig(
audio_encoding=texttospeech.AudioEncoding.MP3,
speaking_rate=0.75,
pitch=-1.0,
)
ssml = (
"<speak>"
+ "<p>Práve je {} a {}.</p>".format(hodiny(hours), minuty(minutes))
+ "</speak>"
)
synthesis_input = texttospeech.SynthesisInput(ssml=ssml)
response = client.synthesize_speech(
input=synthesis_input, voice=voice, audio_config=audio_config
)
filename = "times/%02dh-%02dm.mp3" % (
hours,
minutes,
)
logging.info(f"Filename: {filename}")
with open(filename, "wb") as out:
out.write(response.audio_content)
logging.info("Audio content written to file")
except Exception as e:
logging.exception(e)
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
for hours in range(24):
for minutes in range(60):
gen_time(hours, minutes)