Skip to content

Commit 90b2880

Browse files
authored
Merge pull request #5 from Tesla2000/feature/text
Feature/text
2 parents 578d570 + fcecefc commit 90b2880

21 files changed

Lines changed: 410 additions & 91 deletions

Config.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class _VideoElements:
1212

1313

1414
class Config(_VideoElements):
15+
font_size = 12
16+
font_path = "DejaVuSans"
17+
color = "black"
1518
default_height = 100
1619
default_width = 50
1720
symbol_write_speed = 10
@@ -22,20 +25,20 @@ class Config(_VideoElements):
2225
# start_x = -300
2326
start_y = 280
2427

25-
model = "tts-1-hd"
26-
voice = "nova"
28+
model = "tts-1"
29+
voice = "alloy"
2730

2831
root = Path(__file__).parent
29-
open_ai_token = root.joinpath('open_ai_token').read_text()
32+
open_ai_token = root.joinpath("open_ai_token").read_text()
3033
os.environ.setdefault("OPENAI_API_KEY", open_ai_token)
3134
temporary_picture = root / ".ps"
32-
temp_filename = str(root / '.mp4')
33-
images = root / 'images'
34-
output_videos = root / 'output_videos'
35-
output_audios = root / 'output_audios'
36-
last_frames = root / 'last_frames'
37-
first_frame = root / 'first_frame.jpg'
38-
final_videos = root / 'final_videos'
35+
temp_filename = str(root / ".mp4")
36+
images = root / "images"
37+
output_videos = root / "output_videos"
38+
output_audios = root / "output_audios"
39+
last_frames = root / "last_frames"
40+
first_frame = root / "first_frame.jpg"
41+
final_videos = root / "final_videos"
3942
scripts_package = root / "scripts"
4043
output_videos.mkdir(exist_ok=True)
4144
images.mkdir(exist_ok=True)
@@ -52,16 +55,21 @@ class Config(_VideoElements):
5255
@staticmethod
5356
def audio_name_normalization(text: str) -> str:
5457
polish_to_english = {
55-
'ą': 'a',
56-
'ć': 'c',
57-
'ę': 'e',
58-
'ł': 'l',
59-
'ń': 'n',
60-
'ó': 'o',
61-
'ś': 's',
62-
'ż': 'z',
63-
'ź': 'z',
64-
' ': '_',
58+
"ą": "a",
59+
"ć": "c",
60+
"ę": "e",
61+
"ł": "l",
62+
"ń": "n",
63+
"ó": "o",
64+
"ś": "s",
65+
"ż": "z",
66+
"ź": "z",
67+
" ": "_",
6568
}
66-
return ''.join(
67-
polish_to_english.get(letter, letter) for letter in re.sub(r'[,\.?!]', '', text.strip()).lower()) + ".mp3"
69+
return (
70+
"".join(
71+
polish_to_english.get(letter, letter)
72+
for letter in re.sub(r"[,.?!]", "", text.strip()).lower()
73+
)
74+
+ ".mp3"
75+
)

PassedVariables.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class PassedVariables:
2+
texts_to_translate = tuple()
3+
record = False
4+
texts = []

audio/generate_audio.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77

88
def generate_audio(text_to_translate: str):
9-
speech_file_path = Config.output_audios.joinpath(Config.audio_name_normalization(text_to_translate))
9+
speech_file_path = Config.output_audios.joinpath(
10+
Config.audio_name_normalization(text_to_translate)
11+
)
1012
if speech_file_path.exists():
1113
return
1214
response = client.audio.speech.create(
@@ -17,5 +19,5 @@ def generate_audio(text_to_translate: str):
1719
response.stream_to_file(speech_file_path)
1820

1921

20-
if __name__ == '__main__':
22+
if __name__ == "__main__":
2123
generate_audio("Przeniesienie wykładnika z ułamka na licznik i mianownik.")

figures/Emphasize.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from math import cos, sin, radians
2+
from turtle import color
3+
4+
from Config import Config
5+
from PassedVariables import PassedVariables
6+
from figures.Figure import Figure
7+
from recording.record_turtle import pu, goto, pd
8+
9+
10+
class Emphasize(Figure):
11+
def __init__(
12+
self, inner: Figure, width: int = None, height: int = None, color: str = "red"
13+
):
14+
super().__init__(width, height)
15+
self.inner = inner
16+
self.color = color
17+
18+
def draw(
19+
self,
20+
width: int = None,
21+
height: int = None,
22+
border_width: int = None,
23+
border_height: int = None,
24+
):
25+
self.x_coor = self.inner.x_coor
26+
self.y_coor = self.inner.y_coor
27+
self.width = self.inner.width
28+
self.height = self.inner.height
29+
super().draw(width, height, border_width, border_height)
30+
31+
def _draw(self, width: int, height: int):
32+
color(self.color)
33+
self._draw_ellipse(self.inner.width * 3 // 4, self.inner.height * 3 // 4)
34+
color(Config.color)
35+
36+
def _draw_ellipse(self, a, b):
37+
pu()
38+
goto(self.x_coor + self.width // 2 + a, self.y_coor - self.height // 2)
39+
pd()
40+
for i in range(361):
41+
PassedVariables.record = False
42+
if i % 90 == 0:
43+
PassedVariables.record = True
44+
x = self.x_coor + a * cos(radians(i)) + self.width // 2
45+
y = self.y_coor + b * sin(radians(i)) - self.height // 2
46+
goto(x, y)

figures/Figure.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from Config import Config
55
from figures import moveto
6-
from recording.record_turtle import pu, pd, fd, rt, lt
6+
from recording.record_turtle import pu, pd
77

88

99
class Figure(ABC):
@@ -12,15 +12,27 @@ class Figure(ABC):
1212
width = Config.default_width
1313
height = Config.default_height
1414

15-
def __init__(self, width: int = None, height: int = None, x_coor: int = None, y_coor: int = None):
15+
def __init__(
16+
self,
17+
width: int = None,
18+
height: int = None,
19+
x_coor: int = None,
20+
y_coor: int = None,
21+
):
1622
self.x_coor = x_coor
1723
self.y_coor = y_coor
1824
if height is not None:
1925
self.height = height
2026
if width is not None:
2127
self.width = width
2228

23-
def draw(self, width: int = None, height: int = None, border_width: int = None, border_height: int = None):
29+
def draw(
30+
self,
31+
width: int = None,
32+
height: int = None,
33+
border_width: int = None,
34+
border_height: int = None,
35+
):
2436
moveto(self.x_coor, self.y_coor)
2537
if width is None:
2638
width = self.width
@@ -34,10 +46,21 @@ def draw(self, width: int = None, height: int = None, border_width: int = None,
3446
self._draw(width - (border_width or 0), height - (border_height or 0))
3547
pu()
3648

37-
def undo(self, width: int = None, height: int = None, border_width: int = None, border_height: int = None):
49+
def undo(
50+
self,
51+
width: int = None,
52+
height: int = None,
53+
border_width: int = None,
54+
border_height: int = None,
55+
):
3856
color("white")
39-
self.draw(width=width, height=height, border_width=border_width, border_height=border_height)
40-
color("black")
57+
self.draw(
58+
width=width,
59+
height=height,
60+
border_width=border_width,
61+
border_height=border_height,
62+
)
63+
color(Config.color)
4164

4265
@abstractmethod
4366
def _draw(self, width: int, height: int):

figures/Fraction.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55

66

77
class Fraction(Figure):
8-
def __init__(self, numerator: Figure, denominator: Figure, width: int = Config.default_width, height: int = Config.default_height):
8+
def __init__(
9+
self,
10+
numerator: Figure,
11+
denominator: Figure,
12+
width: int = Config.default_width,
13+
height: int = Config.default_height,
14+
):
915
super().__init__(width, height)
1016
self.numerator = numerator
1117
self.denominator = denominator
@@ -22,5 +28,7 @@ def _draw(self, width: int, height: int):
2228
lt(90)
2329
fd(width - Config.minimal_border_width)
2430
self.denominator.x_coor = self.x_coor
25-
self.denominator.y_coor = self.y_coor - height // 2 - Config.minimal_border_width
31+
self.denominator.y_coor = (
32+
self.y_coor - height // 2 - Config.minimal_border_width
33+
)
2634
self.denominator.draw(width, height // 2)

figures/One.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
class One(Figure):
77
width = Config.default_width // 2
88

9-
def __init__(self, width: int = None, height: int = None, x_coor: int = None, y_coor: int = None, centered: bool = False):
9+
def __init__(
10+
self,
11+
width: int = None,
12+
height: int = None,
13+
x_coor: int = None,
14+
y_coor: int = None,
15+
centered: bool = False,
16+
):
1017
super().__init__(width, height, x_coor, y_coor)
1118
self.centered = centered
1219

figures/Parenthesized.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class Parenthesized(Figure):
7-
87
def __init__(self, inner: Figure, width: int = None, height: int = None):
98
super().__init__(width, height)
109
self.inner = inner

figures/Plus.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class Plus(Figure):
88
width = Config.default_width // 2
9+
910
def _draw(self, width: int, height: int):
1011
rt(90)
1112
pu()

figures/RaiseToPower.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44

55
class RaiseToPower(Figure):
6-
7-
def __init__(self, base: Figure, exponent: Figure, width: int = None, height: int = None):
6+
def __init__(
7+
self, base: Figure, exponent: Figure, width: int = None, height: int = None
8+
):
89
super().__init__(width, height)
910
self.base = base
1011
self.exponent = exponent
@@ -20,4 +21,3 @@ def _draw(self, width: int, height: int):
2021
self.exponent.width = width // 4
2122
self.exponent.height = height // 2
2223
self.exponent.draw()
23-

0 commit comments

Comments
 (0)