Added (smart) translation + TTS api#285
Conversation
(cherry picked from commit 6cb631f)
|
I recommend using an Enum for the languages |
|
true actually. but it will be little annoying to make a list of keys and values |
(cherry picked from commit f3ce6a2)
I'll try to make an enum and then make functions/methods to get the data from those enums |
|
Are you aware of what an Enum is?
faretek ***@***.***> schrieb am Mi., 13. Nov. 2024, 18:56:
… I recommend using an Enum for the languages
I'll try to make an enum and then make functions/methods to get the data
from those enums
—
Reply to this email directly, view it on GitHub
<#285 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATCKMZQESLJZP5UROOHINUT2AOHGDAVCNFSM6AAAAABRVDQNBSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINZUGM2TENZXGE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
|
In case you aren't, I suggest reading the documentation at
https://docs.python.org/3/library/enum
<***@***.***> schrieb am Mi., 13. Nov. 2024, 18:59:
… Are you aware of what an Enum is?
faretek ***@***.***> schrieb am Mi., 13. Nov. 2024, 18:56:
> I recommend using an Enum for the languages
>
> I'll try to make an enum and then make functions/methods to get the data
> from those enums
>
> —
> Reply to this email directly, view it on GitHub
> <#285 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ATCKMZQESLJZP5UROOHINUT2AOHGDAVCNFSM6AAAAABRVDQNBSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINZUGM2TENZXGE>
> .
> You are receiving this because you commented.Message ID:
> ***@***.***>
>
|
|
yesnt. i kind of added one but its not very helpful for this use case since i have to search lists having to use .value is also a bit annoying |
|
You should make the function take an instance of the Enum and take the value out of it in the function |
|
That's what Enums are used for (for instance) |
|
i added an enum (afaik its an enum) but it's not helpful for searching the list of languages. i might abstract the code a bit (making a language class) to clean it up a bit |
|
If you use a good IDE (e.g.vs code), the Enum should help you write code
with the Languages
faretek ***@***.***> schrieb am Sa., 16. Nov. 2024, 10:01:
… i added an enum (afaik its an enum) but I s not helpful for searching the
list of languages. i might abstract the code a bit (making a language
class) to clean it up a bit
—
Reply to this email directly, view it on GitHub
<#285 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATCKMZWTC73QFPDU6L4XO3D2A4CXJAVCNFSM6AAAAABRVDQNBSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOBQGQ4DKNRTGY>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
|
the problem is is what i really want is a list of keys and values, and those are easier to do with dictionaries |
|
ill make a languages class to abstract teh stuff a bit actually |
|
there: |
|
hmm. an enum would be nice tho for code completion |
|
easy to add |
|
do i have to inherit from enum? It feels like it would work nicer without it since then you don't need to do .value all the time |
|
oh, i just don't know enums well enough. there is actually an implementation for using for loops with it already |
|
now i will use these for tts and translate |
|
ok hopefully the new commit means its all good |
|
if this gets merged, I'll have to update the scratchblocks part of scralenium since that also has language data |
(cherry picked from commit 765b068)
|
You just need to do .value in the functions that use the enum instances |
TheCommCraft
left a comment
There was a problem hiding this comment.
Possibly change lines 152-156 to
if isinstance(language, str):
if language.lower() in Languages.all_of("code", str.lower):
lang = Languages.find(language.lower(), "code")
elif language.lower() in Languages.all_of("name", str.lower):
lang = Languages.find(language.lower(), apply_func=str.lower)
elif isinstance(language, Languages):
lang = language
|
ill take a look tmrw |
|
ok. i will take a look now |
|
yes, i'm making a few changes to your addition but it works now with any of these settings: import scratchattach as sa
print(sa.translate("hungarian", "radish"))
print(sa.translate(sa.Languages.Hungarian, "radish"))
print(sa.translate(sa.Languages.Hungarian.value, "radish"))
print(sa.translate("hu", "radish")) |
|
i will take a look at the dataclass stuff now |
|
dang, wow dataclasses makes the code a lot more compact, thanks for telling me about that |
|
its basically just a python struct |
i added that now but im not sure how i tell github that i did |
|
the cmn_CN's attributes should be added to chinese_simplified and chinese_traditional since it is just the tts version of Chinese which applies to both simplified and traditional |
…brazilian) (cherry picked from commit 6ce4ff7)
|
added now |
|
also should probably add better error handling - maybe even add more to exceptions.py |
|
maybe i should make an enum for supported tts genders |
|
maybe change supportedlangs file into utils.enums or something |
|
so instead of making a new file for each enum, just put those kinds of things there |
|
ill turn those extra functions (find and all_of) into something that comes under an enumwrapper class |
|
Are you done with the pull request? |
|
yeah i think so |
|
(yes, pls merge 🥺) |
Sorry I didn't see the message |



Used the scratch translation api to make a function in other_apis.py
Also added a supported languages list/dict in the utils folder
This uses the api at https://translate-service.scratch.mit.edu/translate?language={language}&text={text}
Also added a tts api in the same file using:
https://synthesis-service.scratch.mit.edu/synth?locale={language}&gender={gender[0]}&text={text}
Added relevant languages for tts to the languages file in the utils folder asw