yta-audio-narration 0.0.6__py3-none-any.whl → 0.0.7__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.
- yta_audio_narration/voices/tiktok.py +4 -230
- {yta_audio_narration-0.0.6.dist-info → yta_audio_narration-0.0.7.dist-info}/METADATA +2 -1
- {yta_audio_narration-0.0.6.dist-info → yta_audio_narration-0.0.7.dist-info}/RECORD +5 -5
- {yta_audio_narration-0.0.6.dist-info → yta_audio_narration-0.0.7.dist-info}/LICENSE +0 -0
- {yta_audio_narration-0.0.6.dist-info → yta_audio_narration-0.0.7.dist-info}/WHEEL +0 -0
@@ -1,232 +1,6 @@
|
|
1
1
|
"""
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
And you have more projects here:
|
6
|
-
- Project to use Tiktok API and cookie (https://github.com/Steve0929/tiktok-tts)
|
7
|
-
- Pproject to use Tiktok API and session id (https://github.com/oscie57/tiktok-voice)
|
8
|
-
- Project that is install and play (I think) https://github.com/Giooorgiooo/TikTok-Voice-TTS/blob/main/tiktokvoice.py
|
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
|
11
|
-
from yta_audio_narration_common.enums import NarrationLanguage, VoiceEmotion, VoiceSpeed, VoicePitch
|
12
|
-
from yta_audio_narration_common.voice import NarrationVoice
|
13
|
-
from yta_text.handler import TextHandler
|
14
|
-
from yta_file.handler import FileHandler
|
15
|
-
from yta_constants.enum import YTAEnum as Enum
|
16
|
-
from yta_constants.file import FileType
|
17
|
-
from yta_programming.output import Output
|
18
|
-
from typing import Union
|
19
|
-
|
20
|
-
import requests
|
21
|
-
import base64
|
22
|
-
|
23
|
-
|
24
|
-
"""
|
25
|
-
The options below are specified even if we
|
26
|
-
don't use them later when processing the
|
27
|
-
voice narration. This is to keep the same
|
28
|
-
structure for any voice narration and to
|
29
|
-
simplify the way we offer the options in
|
30
|
-
an API that is able to make requests.
|
31
|
-
"""
|
32
|
-
|
33
|
-
# 1. The voices we accept, as Enums
|
34
|
-
class TiktokVoiceName(Enum):
|
35
|
-
"""
|
36
|
-
Available voices. The value is what is used
|
37
|
-
for the audio creation.
|
38
|
-
"""
|
39
|
-
|
40
|
-
DEFAULT = DEFAULT_VOICE
|
41
|
-
SPANISH = 'es_002'
|
42
|
-
MEXICAN = 'es_mx_002'
|
43
|
-
# TODO: There a a lot of English US and more languages voices
|
44
|
-
|
45
|
-
# 2. The languages we accept
|
46
|
-
LANGUAGE_OPTIONS = [
|
47
|
-
NarrationLanguage.SPANISH,
|
48
|
-
NarrationLanguage.DEFAULT
|
49
|
-
]
|
50
|
-
|
51
|
-
# 3. The emotions we accept
|
52
|
-
EMOTION_OPTIONS = [
|
53
|
-
VoiceEmotion.DEFAULT,
|
54
|
-
VoiceEmotion.NORMAL,
|
55
|
-
]
|
56
|
-
|
57
|
-
# 4. The speeds we accept
|
58
|
-
SPEED_OPTIONS = [
|
59
|
-
VoiceSpeed.DEFAULT,
|
60
|
-
VoiceSpeed.NORMAL,
|
61
|
-
]
|
62
|
-
|
63
|
-
# 5. The pitches we accept
|
64
|
-
PITCH_OPTIONS = [
|
65
|
-
VoicePitch.DEFAULT,
|
66
|
-
VoicePitch.NORMAL,
|
67
|
-
]
|
68
|
-
|
69
|
-
class TiktokNarrationVoice(NarrationVoice):
|
70
|
-
"""
|
71
|
-
Voice instance to be used when narrating with
|
72
|
-
Tiktok engine.
|
73
|
-
"""
|
74
|
-
|
75
|
-
@property
|
76
|
-
def processed_name(
|
77
|
-
self
|
78
|
-
) -> str:
|
79
|
-
"""
|
80
|
-
Get the usable name value from the one that has
|
81
|
-
been set when instantiating the instance.
|
82
|
-
"""
|
83
|
-
# TODO: Maybe this DEFAULT value has to exist
|
84
|
-
# for each language so it chooses one voice name
|
85
|
-
# for that language
|
86
|
-
return (
|
87
|
-
TiktokVoiceName.SPANISH.value
|
88
|
-
if TiktokVoiceName.to_enum(self.name) == TiktokVoiceName.DEFAULT else
|
89
|
-
TiktokVoiceName.to_enum(self.name).value
|
90
|
-
)
|
91
|
-
|
92
|
-
@property
|
93
|
-
def processed_emotion(
|
94
|
-
self
|
95
|
-
) -> str:
|
96
|
-
"""
|
97
|
-
Get the usable emotion value from the one that
|
98
|
-
has been set when instantiating the instance.
|
99
|
-
"""
|
100
|
-
# This narration is not able to handle any
|
101
|
-
# emotion (at least by now)
|
102
|
-
return None
|
103
|
-
|
104
|
-
@property
|
105
|
-
def processed_speed(
|
106
|
-
self
|
107
|
-
) -> int:
|
108
|
-
"""
|
109
|
-
Get the usable speed value from the one that
|
110
|
-
has been set when instantiating the instance.
|
111
|
-
"""
|
112
|
-
# This is not used here
|
113
|
-
return None
|
114
|
-
|
115
|
-
@property
|
116
|
-
def processed_pitch(
|
117
|
-
self
|
118
|
-
) -> int:
|
119
|
-
"""
|
120
|
-
Get the usable pitch value from the one that
|
121
|
-
has been set when instantiating the instance.
|
122
|
-
"""
|
123
|
-
# This is not used here
|
124
|
-
return None
|
125
|
-
|
126
|
-
@property
|
127
|
-
def processed_language(
|
128
|
-
self
|
129
|
-
) -> str:
|
130
|
-
"""
|
131
|
-
Get the usable language value from the one that
|
132
|
-
has been set when instantiating the instance.
|
133
|
-
"""
|
134
|
-
# TODO: There is not language associated with this
|
135
|
-
# narration voice engine. The language is set in
|
136
|
-
# the voice name
|
137
|
-
return None
|
138
|
-
|
139
|
-
def validate_and_process(
|
140
|
-
self,
|
141
|
-
name: str,
|
142
|
-
emotion: VoiceEmotion,
|
143
|
-
speed: VoiceSpeed,
|
144
|
-
pitch: VoicePitch,
|
145
|
-
language: NarrationLanguage
|
146
|
-
):
|
147
|
-
TiktokVoiceName.to_enum(name)
|
148
|
-
if VoiceEmotion.to_enum(emotion) not in EMOTION_OPTIONS:
|
149
|
-
raise Exception(f'The provided {emotion} is not valid for this narration voice.')
|
150
|
-
if VoiceSpeed.to_enum(speed) not in SPEED_OPTIONS:
|
151
|
-
raise Exception(f'The provided {speed} is not valid for this narration voice.')
|
152
|
-
if VoicePitch.to_enum(pitch) not in PITCH_OPTIONS:
|
153
|
-
raise Exception(f'The provided {pitch} is not valid for this narration voice.')
|
154
|
-
if NarrationLanguage.to_enum(language) not in LANGUAGE_OPTIONS:
|
155
|
-
raise Exception(f'The provided {language} is not valid for this narration voice.')
|
156
|
-
|
157
|
-
@staticmethod
|
158
|
-
def default():
|
159
|
-
return TiktokNarrationVoice(
|
160
|
-
name = TiktokVoiceName.DEFAULT.value,
|
161
|
-
emotion = VoiceEmotion.DEFAULT,
|
162
|
-
speed = VoiceSpeed.DEFAULT,
|
163
|
-
pitch = VoicePitch.DEFAULT,
|
164
|
-
language = NarrationLanguage.DEFAULT
|
165
|
-
)
|
166
|
-
|
167
|
-
# The voices but for a specific language, to be able to
|
168
|
-
# choose one when this is requested from the outside
|
169
|
-
def get_narrator_names_by_language(
|
170
|
-
language: NarrationLanguage
|
171
|
-
) -> list[str]:
|
172
|
-
language = NarrationLanguage.to_enum(language)
|
173
|
-
language = (
|
174
|
-
NarrationLanguage.SPANISH
|
175
|
-
if language is NarrationLanguage.DEFAULT else
|
176
|
-
language
|
177
|
-
)
|
178
|
-
|
179
|
-
return {
|
180
|
-
NarrationLanguage.SPANISH: [
|
181
|
-
TiktokVoiceName.DEFAULT.value,
|
182
|
-
TiktokVoiceName.SPANISH.value,
|
183
|
-
TiktokVoiceName.MEXICAN.value
|
184
|
-
]
|
185
|
-
}[language]
|
186
|
-
|
187
|
-
# All the remaining functionality we need to make it
|
188
|
-
# work properly
|
189
|
-
def narrate_tiktok(
|
190
|
-
text: str,
|
191
|
-
voice: TiktokNarrationVoice = TiktokNarrationVoice.default(),
|
192
|
-
output_filename: Union[str, None] = None
|
193
|
-
) -> str:
|
194
|
-
"""
|
195
|
-
This is the tiktok voice based on a platform that generates it.
|
196
|
-
This will make a narration with the tiktok voice. You can
|
197
|
-
change the code to use the mexican voice.
|
198
|
-
|
199
|
-
As this is based on an external platform, it could fail.
|
200
|
-
|
201
|
-
This method returns the filename that has been written.
|
202
|
-
"""
|
203
|
-
headers = {
|
204
|
-
'accept': '*/*',
|
205
|
-
'accept-language': 'es-ES,es;q=0.9',
|
206
|
-
'content-type': 'text/plain;charset=UTF-8',
|
207
|
-
'origin': 'https://gesserit.co',
|
208
|
-
'referer': 'https://gesserit.co/tiktok',
|
209
|
-
'sec-ch-ua': '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"',
|
210
|
-
'sec-ch-ua-mobile': '?0',
|
211
|
-
'sec-ch-ua-platform': '"Windows"',
|
212
|
-
'sec-fetch-dest': 'empty',
|
213
|
-
'sec-fetch-mode': 'cors',
|
214
|
-
'sec-fetch-site': 'same-origin',
|
215
|
-
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
|
216
|
-
}
|
217
|
-
|
218
|
-
# Non-English characters are not accepted by Tiktok TTS generation, so:
|
219
|
-
text = TextHandler.remove_non_ascii_characters(text)
|
220
|
-
|
221
|
-
#data = f'{"text":"{text}","voice":"{voice.name}"}'
|
222
|
-
data = '{"text":"' + text + '","voice":"' + voice.processed_name + '"}'
|
223
|
-
|
224
|
-
base64_content = requests.post('https://gesserit.co/api/tiktok-tts', headers = headers, data = data).json()['base64']
|
225
|
-
|
226
|
-
output_filename = Output.get_filename(output_filename, FileType.AUDIO)
|
227
|
-
|
228
|
-
return FileHandler.write_binary(
|
229
|
-
filename = output_filename,
|
230
|
-
binary_data = base64.b64decode(base64_content)
|
231
|
-
)
|
232
|
-
|
6
|
+
from yta_audio_narration_tiktok import TiktokVoiceName, LANGUAGE_OPTIONS, EMOTION_OPTIONS, SPEED_OPTIONS, PITCH_OPTIONS, TiktokNarrationVoice, get_narrator_names_by_language, narrate_tiktok
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: yta-audio-narration
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.7
|
4
4
|
Summary: Youtube Autonomous Audio Narration Module.
|
5
5
|
Author: danialcala94
|
6
6
|
Author-email: danielalcalavalera@gmail.com
|
@@ -13,6 +13,7 @@ Requires-Dist: yta_audio_narration_google (>=0.0.1,<1.0.0)
|
|
13
13
|
Requires-Dist: yta_audio_narration_microsoft (>=0.0.1,<1.0.0)
|
14
14
|
Requires-Dist: yta_audio_narration_open_voice (>=0.0.1,<1.0.0)
|
15
15
|
Requires-Dist: yta_audio_narration_tetyys (>=0.0.1,<1.0.0)
|
16
|
+
Requires-Dist: yta_audio_narration_tiktok (>=0.0.1,<1.0.0)
|
16
17
|
Requires-Dist: yta_constants (>=0.0.1,<1.0.0)
|
17
18
|
Requires-Dist: yta_file (>=0.0.1,<1.0.0)
|
18
19
|
Requires-Dist: yta_file_downloader (>=0.0.1,<1.0.0)
|
@@ -7,10 +7,10 @@ yta_audio_narration/voices/google.py,sha256=I4L2qm-zIXJ7eE23iM88m8rdEtO9L820vbnR
|
|
7
7
|
yta_audio_narration/voices/microsoft.py,sha256=DnMyc2C5Zy2VEpYK2Xljsrhx8QibUPlIrXAKTUD6uTI,318
|
8
8
|
yta_audio_narration/voices/open_voice.py,sha256=zU4LmXVAHgF3YCMrM--55RM1UGQX7kn9Y2137wCNu1Y,347
|
9
9
|
yta_audio_narration/voices/tetyys.py,sha256=CFVpUJLA_SK7_wMBnhl4mlPNgI-VKvxXy0aX7MvxoxE,316
|
10
|
-
yta_audio_narration/voices/tiktok.py,sha256=
|
10
|
+
yta_audio_narration/voices/tiktok.py,sha256=hX-u3Aqlu93IxahnrWGoGYIPJCPelsv7lxaxjoX1blE,316
|
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.
|
14
|
-
yta_audio_narration-0.0.
|
15
|
-
yta_audio_narration-0.0.
|
16
|
-
yta_audio_narration-0.0.
|
13
|
+
yta_audio_narration-0.0.7.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
14
|
+
yta_audio_narration-0.0.7.dist-info/METADATA,sha256=HUUMPaEtFaK_OUZytbBwmFfcNv0I6zPKbfFdMCNXU74,1176
|
15
|
+
yta_audio_narration-0.0.7.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
16
|
+
yta_audio_narration-0.0.7.dist-info/RECORD,,
|
File without changes
|
File without changes
|