yta-audio-narration 0.0.2__py3-none-any.whl → 0.0.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,266 +1,6 @@
1
1
  """
2
- This link could be interesting:
3
- - https://github.com/DarinRowe/googletrans
4
-
5
- You have a lot of information here:
6
- - https://en.wikipedia.org/wiki/IETF_language_tag
7
- - https://pypi.org/project/langcodes/
8
- - https://gtts.readthedocs.io/en/latest/module.html#languages-gtts-lang
2
+ TODO: Do we make this optional or not? If it
3
+ is optional we can allow installing the libs
4
+ only if using this one.
9
5
  """
10
- from yta_audio_narration_common.consts import DEFAULT_VOICE
11
- from yta_audio_narration_common.enums import NarrationLanguage, VoiceEmotion, VoiceSpeed, VoicePitch
12
- from yta_audio_narration_common.voice import NarrationVoice
13
- from yta_constants.enum import YTAEnum as Enum
14
- from yta_constants.file import FileType
15
- from yta_programming.output import Output
16
- from typing import Union
17
- from gtts import gTTS
18
-
19
-
20
- """
21
- This specific voice narration engine needs
22
- specific values and a different parameter
23
- handling.
24
- """
25
-
26
- class GoogleNarrationLanguage(Enum):
27
- """
28
- The google narration languages accepted by their
29
- API
30
- """
31
-
32
- SPANISH = 'es'
33
- ENGLISH = 'en'
34
-
35
- @staticmethod
36
- def from_general_language(
37
- language: NarrationLanguage
38
- ) -> 'GoogleNarrationLanguage':
39
- """
40
- Turn a general 'language' instance into a Google
41
- narration language instance.
42
- """
43
- return {
44
- NarrationLanguage.DEFAULT: GoogleNarrationLanguage.SPANISH,
45
- NarrationLanguage.SPANISH: GoogleNarrationLanguage.SPANISH,
46
- NarrationLanguage.ENGLISH: GoogleNarrationLanguage.ENGLISH,
47
- }[NarrationLanguage.to_enum(language)]
48
-
49
- """
50
- The options below are specified even if we
51
- don't use them later when processing the
52
- voice narration. This is to keep the same
53
- structure for any voice narration and to
54
- simplify the way we offer the options in
55
- an API that is able to make requests.
56
-
57
- If the engine doesn't have one specific
58
- option (I mean, you cannot handle the
59
- narration speed, for example) we will allow
60
- the user choose 'normal' value and it will
61
- be handled just by ignoring it, but the user
62
- will be able to choose it.
63
- """
64
-
65
- # 1. The voices we accept, as Enums
66
- class GoogleTld(Enum):
67
-
68
- DEFAULT = DEFAULT_VOICE
69
- SPANISH_SPAIN = 'es'
70
- SPANISH_MEXICO = 'com.mx'
71
- SPANISH_US = 'us'
72
- # TODO: How can I get the list of Tlds?I need it
73
-
74
- @staticmethod
75
- def from_google_language(
76
- language: GoogleNarrationLanguage
77
- ) -> 'GoogleTld':
78
- """
79
- Turn the Google narration 'language' into the
80
- corresponding Google TLD.
81
- """
82
- return {
83
- GoogleNarrationLanguage.SPANISH: GoogleTld.SPANISH_SPAIN,
84
- # TODO: Change this
85
- GoogleNarrationLanguage.ENGLISH: GoogleTld.SPANISH_US,
86
- }[GoogleNarrationLanguage.to_enum(language)]
87
-
88
- # 2. The languages we accept
89
- LANGUAGE_OPTIONS = [
90
- NarrationLanguage.SPANISH,
91
- # TODO: Unavailable until I detect some valid TLDs
92
- #NarrationLanguage.ENGLISH,
93
- NarrationLanguage.DEFAULT
94
- ]
95
-
96
- # 3. The emotions we accept
97
- EMOTION_OPTIONS = [
98
- VoiceEmotion.DEFAULT,
99
- VoiceEmotion.NORMAL,
100
- ]
101
-
102
- # 4. The speeds we accept
103
- SPEED_OPTIONS = [
104
- VoiceSpeed.DEFAULT,
105
- VoiceSpeed.NORMAL,
106
- VoiceSpeed.SLOW,
107
- ]
108
-
109
- # 5. The pitches we accept
110
- PITCH_OPTIONS = [
111
- VoicePitch.DEFAULT,
112
- VoicePitch.NORMAL,
113
- ]
114
-
115
-
116
- class GoogleNarrationVoice(NarrationVoice):
117
- """
118
- Voice instance to be used when narrating with
119
- Google engine.
120
- """
121
-
122
- @property
123
- def processed_name(
124
- self
125
- ) -> str:
126
- """
127
- Get the usable name value from the one that has
128
- been set when instantiating the instance.
129
- """
130
- # TODO: Maybe this DEFAULT value has to exist
131
- # for each language so it chooses one voice name
132
- # for that language
133
- return (
134
- GoogleTld.SPANISH_SPAIN.value
135
- if GoogleTld.to_enum(self.name) == GoogleTld.DEFAULT else
136
- GoogleTld.to_enum(self.name).value
137
- )
138
-
139
- @property
140
- def processed_emotion(
141
- self
142
- ) -> str:
143
- """
144
- Get the usable emotion value from the one that
145
- has been set when instantiating the instance.
146
- """
147
- # This narration is not able to handle any
148
- # emotion (at least by now)
149
- return None
150
-
151
- @property
152
- def processed_speed(
153
- self
154
- ) -> bool:
155
- """
156
- Get the usable speed value from the one that
157
- has been set when instantiating the instance.
158
- """
159
- # This value is actually saying if we are using
160
- # the slow mode or not
161
- return {
162
- VoiceSpeed.SLOW: True,
163
- VoiceSpeed.DEFAULT: False,
164
- VoiceSpeed.NORMAL: False
165
- }[self.speed]
166
-
167
- @property
168
- def processed_pitch(
169
- self
170
- ) -> float:
171
- """
172
- Get the usable pitch value from the one that
173
- has been set when instantiating the instance.
174
- """
175
- # By now we are not handling the pitch with
176
- # this voice
177
- return None
178
-
179
- @property
180
- def processed_language(
181
- self
182
- ) -> str:
183
- """
184
- Get the usable language value from the one that
185
- has been set when instantiating the instance.
186
- """
187
- return GoogleNarrationLanguage.from_general_language(self.language).value
188
-
189
- def validate_and_process(
190
- self,
191
- name: str,
192
- emotion: VoiceEmotion,
193
- speed: VoiceSpeed,
194
- pitch: VoicePitch,
195
- language: NarrationLanguage
196
- ):
197
- GoogleTld.to_enum(name)
198
- if VoiceEmotion.to_enum(emotion) not in EMOTION_OPTIONS:
199
- raise Exception(f'The provided {emotion} is not valid for this narration voice.')
200
- if VoiceSpeed.to_enum(speed) not in SPEED_OPTIONS:
201
- raise Exception(f'The provided {speed} is not valid for this narration voice.')
202
- if VoicePitch.to_enum(pitch) not in PITCH_OPTIONS:
203
- raise Exception(f'The provided {pitch} is not valid for this narration voice.')
204
- if NarrationLanguage.to_enum(language) not in LANGUAGE_OPTIONS:
205
- raise Exception(f'The provided {language} is not valid for this narration voice.')
206
-
207
- @staticmethod
208
- def default():
209
- return GoogleNarrationVoice(
210
- name = GoogleTld.DEFAULT.value,
211
- emotion = VoiceEmotion.DEFAULT,
212
- speed = VoiceSpeed.DEFAULT,
213
- pitch = VoicePitch.DEFAULT,
214
- language = NarrationLanguage.DEFAULT
215
- )
216
- # TODO: This was in the previous version, remove when
217
- # confirmed that the above is working
218
- # return GoogleNarrationVoice('', '', 130, 1.0, NarrationLanguage.DEFAULT)
219
-
220
- # The voices but for a specific language, to be able to
221
- # choose one when this is requested from the outside
222
- def get_narrator_names_by_language(
223
- language: NarrationLanguage
224
- ) -> list[str]:
225
- language = NarrationLanguage.to_enum(language)
226
- language = (
227
- NarrationLanguage.SPANISH
228
- if language is NarrationLanguage.DEFAULT else
229
- language
230
- )
231
-
232
- return {
233
- NarrationLanguage.SPANISH: [
234
- GoogleTld.DEFAULT.value,
235
- GoogleTld.SPANISH_SPAIN.value,
236
- GoogleTld.SPANISH_MEXICO.value,
237
- GoogleTld.SPANISH_US.value
238
- ]
239
- }[language]
240
-
241
-
242
- # All the remaining functionality we need to make it
243
- # work properly
244
- def narrate(
245
- text: str,
246
- voice: GoogleNarrationVoice = GoogleNarrationVoice.default(),
247
- output_filename: Union[str, None] = None
248
- ):
249
- """
250
- Creates an audio narration of the provided 'text' with the Google voice and stores it
251
- as 'output_filename'. This will use the provided 'language' language for the narration.
252
- """
253
- output_filename = Output.get_filename(output_filename, FileType.AUDIO)
254
-
255
- tld = GoogleTld.from_google_language(voice.processed_language).value
256
-
257
- gTTS(
258
- text = text,
259
- lang = voice.processed_language,
260
- tld = tld,
261
- slow = voice.processed_speed
262
- ).save(
263
- output_filename
264
- )
265
-
266
- return output_filename
6
+ from yta_audio_narration_google import GoogleNarrationLanguage, GoogleTld, LANGUAGE_OPTIONS, EMOTION_OPTIONS, SPEED_OPTIONS, PITCH_OPTIONS, GoogleNarrationVoice, get_narrator_names_by_language, narrate
@@ -1,209 +1,6 @@
1
- from yta_audio_narration_common.enums import NarrationLanguage, VoiceEmotion, VoiceSpeed, VoicePitch
2
- from yta_audio_narration_common.consts import DEFAULT_VOICE
3
- from yta_audio_narration_common.voice import NarrationVoice
4
- from yta_constants.enum import YTAEnum as Enum
5
- from yta_constants.file import FileType
6
- from yta_programming.output import Output
7
- from typing import Union
8
-
9
- import pyttsx3
10
-
11
-
12
1
  """
13
- The options below are specified even if we
14
- don't use them later when processing the
15
- voice narration. This is to keep the same
16
- structure for any voice narration and to
17
- simplify the way we offer the options in
18
- an API that is able to make requests.
2
+ TODO: Do we make this optional or not? If it
3
+ is optional we can allow installing the libs
4
+ only if using this one.
19
5
  """
20
-
21
- # 1. The voices we accept, as Enums
22
- class MicrosoftVoiceName(Enum):
23
- """
24
- Available voices. The value is what is used
25
- for the audio creation.
26
- """
27
-
28
- DEFAULT = DEFAULT_VOICE
29
- SPANISH_SPAIN = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_ES-ES_HELENA_11.0'
30
- SPANISH_MEXICO = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_ES-MX_SABINA_11.0'
31
- # TODO: There are more voices
32
-
33
- # 2. The languages we accept
34
- LANGUAGE_OPTIONS = [
35
- NarrationLanguage.DEFAULT,
36
- NarrationLanguage.SPANISH
37
- ]
38
-
39
- # 3. The emotions we accept
40
- EMOTION_OPTIONS = [
41
- VoiceEmotion.DEFAULT,
42
- VoiceEmotion.NORMAL,
43
- ]
44
-
45
- # 4. The speeds we accept
46
- SPEED_OPTIONS = [
47
- VoiceSpeed.DEFAULT,
48
- VoiceSpeed.NORMAL,
49
- VoiceSpeed.SLOW,
50
- VoiceSpeed.FAST
51
- ]
52
-
53
- # 5. The pitches we accept
54
- PITCH_OPTIONS = [
55
- VoicePitch.DEFAULT,
56
- VoicePitch.NORMAL,
57
- ]
58
-
59
-
60
- class MicrosoftNarrationVoice(NarrationVoice):
61
- """
62
- Voice instance to be used when narrating with
63
- Microsoft engine.
64
- """
65
-
66
- @property
67
- def processed_name(
68
- self
69
- ) -> str:
70
- """
71
- Get the usable name value from the one that has
72
- been set when instantiating the instance.
73
- """
74
- # TODO: Maybe this DEFAULT value has to exist
75
- # for each language so it chooses one voice name
76
- # for that language
77
- return (
78
- MicrosoftVoiceName.SPANISH_SPAIN.value
79
- if MicrosoftVoiceName.to_enum(self.name) == MicrosoftVoiceName.DEFAULT else
80
- MicrosoftVoiceName.to_enum(self.name).value
81
- )
82
-
83
- @property
84
- def processed_emotion(
85
- self
86
- ) -> str:
87
- """
88
- Get the usable emotion value from the one that
89
- has been set when instantiating the instance.
90
- """
91
- # This narration is not able to handle any
92
- # emotion (at least by now)
93
- return None
94
-
95
- @property
96
- def processed_speed(
97
- self
98
- ) -> int:
99
- """
100
- Get the usable speed value from the one that
101
- has been set when instantiating the instance.
102
- """
103
- # This value is actually the amount of words per
104
- # minute to be said during the speech
105
- speed = (
106
- VoiceSpeed.NORMAL
107
- if self.speed == VoiceSpeed.DEFAULT else
108
- self.speed
109
- )
110
-
111
- return {
112
- VoiceSpeed.SLOW: 160,
113
- VoiceSpeed.NORMAL: 200,
114
- VoiceSpeed.FAST: 240
115
- }[speed]
116
-
117
- @property
118
- def processed_pitch(
119
- self
120
- ) -> float:
121
- """
122
- Get the usable pitch value from the one that
123
- has been set when instantiating the instance.
124
- """
125
- # By now we are not handling the pitch with
126
- # this voice
127
- return None
128
-
129
- @property
130
- def processed_language(
131
- self
132
- ) -> str:
133
- """
134
- Get the usable language value from the one that
135
- has been set when instantiating the instance.
136
- """
137
- # By now we are not handling the language with
138
- # this voice
139
- return None
140
-
141
- def validate_and_process(
142
- self,
143
- name: str,
144
- emotion: VoiceEmotion,
145
- speed: VoiceSpeed,
146
- pitch: VoicePitch,
147
- language: NarrationLanguage
148
- ):
149
- MicrosoftVoiceName.to_enum(name)
150
- if VoiceEmotion.to_enum(emotion) not in EMOTION_OPTIONS:
151
- raise Exception(f'The provided {emotion} is not valid for this narration voice.')
152
- if VoiceSpeed.to_enum(speed) not in SPEED_OPTIONS:
153
- raise Exception(f'The provided {speed} is not valid for this narration voice.')
154
- if VoicePitch.to_enum(pitch) not in PITCH_OPTIONS:
155
- raise Exception(f'The provided {pitch} is not valid for this narration voice.')
156
- if NarrationLanguage.to_enum(language) not in LANGUAGE_OPTIONS:
157
- raise Exception(f'The provided {language} is not valid for this narration voice.')
158
-
159
- @staticmethod
160
- def default():
161
- return MicrosoftNarrationVoice(
162
- name = MicrosoftVoiceName.DEFAULT.value,
163
- emotion = VoiceEmotion.DEFAULT,
164
- speed = VoiceSpeed.DEFAULT,
165
- pitch = VoicePitch.DEFAULT,
166
- language = NarrationLanguage.DEFAULT
167
- )
168
-
169
- # The voices but for a specific language, to be able to
170
- # choose one when this is requested from the outside
171
- def get_narrator_names_by_language(
172
- language: NarrationLanguage
173
- ) -> list[str]:
174
- language = NarrationLanguage.to_enum(language)
175
- language = (
176
- NarrationLanguage.SPANISH
177
- if language is NarrationLanguage.DEFAULT else
178
- language
179
- )
180
-
181
- return {
182
- NarrationLanguage.SPANISH: [
183
- MicrosoftVoiceName.DEFAULT.value,
184
- MicrosoftVoiceName.SPANISH_SPAIN.value,
185
- MicrosoftVoiceName.SPANISH_MEXICO.value
186
- ]
187
- }[language]
188
-
189
- # All the remaining functionality we need to make it
190
- # work properly
191
- def narrate(
192
- text: str,
193
- voice: MicrosoftNarrationVoice = MicrosoftNarrationVoice.default(),
194
- output_filename: Union[str, None] = None
195
- ):
196
- """
197
- Creates an audio narration of the provided 'text'
198
- and stores it as 'output_filename'.
199
- """
200
- output_filename = Output.get_filename(output_filename, FileType.AUDIO)
201
-
202
- engine = pyttsx3.init()
203
- engine.setProperty('voice', voice.processed_name)
204
- # Default speed is 200 (wpm)
205
- engine.setProperty('rate', voice.processed_speed)
206
- engine.save_to_file(text, output_filename)
207
- engine.runAndWait()
208
-
209
- return output_filename
6
+ from yta_audio_narration_microsoft import MicrosoftNarrationLanguage, LANGUAGE_OPTIONS, EMOTION_OPTIONS, SPEED_OPTIONS, PITCH_OPTIONS, MicrosoftNarrationVoice, get_narrator_names_by_language, narrate
@@ -1,16 +1,16 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: yta-audio-narration
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Youtube Autonomous Audio Narration Module.
5
5
  Author: danialcala94
6
6
  Author-email: danielalcalavalera@gmail.com
7
7
  Requires-Python: ==3.9
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Programming Language :: Python :: 3.9
10
- Requires-Dist: gtts (>=2.5.1,<3.0.0)
11
- Requires-Dist: pyttsx3 (>=2.90,<3.0)
12
10
  Requires-Dist: yta_audio_narration_common (>=0.0.1,<1.0.0)
13
11
  Requires-Dist: yta_audio_narration_coqui (>=0.0.1,<1.0.0)
12
+ Requires-Dist: yta_audio_narration_google (>=0.0.1,<1.0.0)
13
+ Requires-Dist: yta_audio_narration_microsoft (>=0.0.1,<1.0.0)
14
14
  Requires-Dist: yta_constants (>=0.0.1,<1.0.0)
15
15
  Requires-Dist: yta_file (>=0.0.1,<1.0.0)
16
16
  Requires-Dist: yta_file_downloader (>=0.0.1,<1.0.0)
@@ -3,14 +3,14 @@ yta_audio_narration/enums.py,sha256=AsGCuRldH4Fa4XHMcS0SS1J_J6hAAKGo9rJ9ONd3erQ,
3
3
  yta_audio_narration/narrator.py,sha256=w-ACkH71vGhgAJxD1H3ToPDa3HQZOs5W0f1okeqyznE,20459
4
4
  yta_audio_narration/voices/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  yta_audio_narration/voices/coqui.py,sha256=e3-AOTW-IS9L9aYFrp-_sSE543vygKupW96xgYhL0cI,331
6
- yta_audio_narration/voices/google.py,sha256=ahK5MjxqsKQrx1lkmUVGZWs5MacNHyNUNww0qN0RzwM,8131
7
- yta_audio_narration/voices/microsoft.py,sha256=J5e4153secyta5tEWeNJTBYkkFhVYbM1zQ-e9y73Yr8,6375
6
+ yta_audio_narration/voices/google.py,sha256=I4L2qm-zIXJ7eE23iM88m8rdEtO9L820vbnRJbQHhsg,328
7
+ yta_audio_narration/voices/microsoft.py,sha256=6N1b5y4ayCPg5WdxhHZAVKSPCH3kta_J6YhDc3nVoB8,326
8
8
  yta_audio_narration/voices/open_voice.py,sha256=KlqIcsJXY581dURIqaFdk8noHsllzxZbQCkSyBxQ7QM,12981
9
9
  yta_audio_narration/voices/tetyys.py,sha256=PZB8CSkdAyStWsWwMqRvm0dlEefZViO5fcwwzNZE9IM,8291
10
10
  yta_audio_narration/voices/tiktok.py,sha256=R1lWljr0on_wamKBOUo9mbHXkmKvPbGYk2Ebfm6ua50,7482
11
11
  yta_audio_narration/voices/tortoise.py,sha256=qtL7Hl2f2bSjw2G81Ui-lTV8DZIcrJrKClkY3ulkf3I,6576
12
12
  yta_audio_narration/voices/ttsmp3.py,sha256=Zl3w4uY9n93RlpQv8c_1w22KZlb5BzHQRAqsheu5Gbo,8799
13
- yta_audio_narration-0.0.2.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
14
- yta_audio_narration-0.0.2.dist-info/METADATA,sha256=43P7R0_QkDTD-xYCzhJNpiqqe0s_9Xv7nOCC8Ku_wNs,948
15
- yta_audio_narration-0.0.2.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
16
- yta_audio_narration-0.0.2.dist-info/RECORD,,
13
+ yta_audio_narration-0.0.4.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
14
+ yta_audio_narration-0.0.4.dist-info/METADATA,sha256=D8D9saJl2JFiKQPQKB4qTKZh1dHSMkDYu-sWZN9pGB4,995
15
+ yta_audio_narration-0.0.4.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
16
+ yta_audio_narration-0.0.4.dist-info/RECORD,,