diff --git a/.gitignore b/.gitignore index d91d316..b93b161 100644 --- a/.gitignore +++ b/.gitignore @@ -30,7 +30,7 @@ MANIFEST # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest -*.spec +#*.spec # Installer logs pip-log.txt diff --git a/README.md b/README.md index 42e329f..6364fb7 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Directories: Besides those directories, there are also these two files in the root (apart from the .gitignore, README.md and LICENSE): -- `audiotext.spec`: Used to generate a .exe file with [PyInstaller](https://pyinstaller.org/en/stable/). Notice that, inside the file, there are some annotations, which are `ROOT DIRECTORY PATH`, `PATH TO CUSTOM TKINTER` and `PATH TO RES FOLDER`. You will have to replace them by the indicated path of your computer. For example, my `PATH TO CUSTOMTKINTER` is `c:\\users\\JC\\appdata\\local\\programs\\python\\python310\\lib\\site-packages\\customtkinter`. +- `audiotext.spec`: Used to generate a .exe file with [PyInstaller](https://pyinstaller.org/en/stable/). Notice that, inside the file, there are is the annotation `PATH TO CUSTOM TKINTER`. You will have to replace it by the actual path in your computer. To get it, you can execute `pip show customtkinter`. - `requirements.txt`: Lists the names and versions of each package used to build this project.

(back to top)

@@ -92,7 +92,7 @@ Besides those directories, there are also these two files in the root (apart fro ## Getting Started -**Important**: You need to install [FFmpeg](https://ffmpeg.org) to execute the program. Otherwise, it won't be able to process the audio files. You can download FFmpeg from the [official site](https://ffmpeg.org/download.html) +**Important**: You need to install [FFmpeg](https://ffmpeg.org) to execute the program. Otherwise, it won't be able to process the audio files. You can download FFmpeg from the [official site](https://ffmpeg.org/download.html). If you want to execute the program: - Go to [releases](https://github.com/HenestrosaConH/audiotext/releases) and download the latest one. Once you download it and uncompress it, open the `audiotext` folder and open the `audiotext.exe` file. @@ -102,6 +102,7 @@ If you want to open the code: - Please bear in mind that you cannot generate a single .exe file for this project with PyInstaller due to the dependency with the CustomTkinter package (reason [here](https://github.com/TomSchimansky/CustomTkinter/wiki/Packaging)). - It's crucial to note that I've had to comment out the line `pprint(response_text, indent=4)` in the `recognize_google` function from the `__init__.py` file of the `SpeechRecognition` package. If it wasn't commented, the project would need to run a command line along with the GUI. Otherwise, the program wouldn't run when calling this function because the mentioned line throws an error that stops the function from running (in case that the program doesn't run on a console), which cannot be handled within the project code. - Similar to the point above, the lines 159, 160 and 176 of the file `ffmpeg_audiowriter` from the `moviepy` package are commented for the same reason stated above. There is also a change in the line 169. `logger=logger` has been changed to `logger=None` to avoid more errors related to opening the console. +- For Mac M1 users: There is a problem installing the `pyaudio` library. [Here](https://stackoverflow.com/questions/73268630/error-could-not-build-wheels-for-pyaudio-which-is-required-to-install-pyprojec) is a StackOverflow post explaining how to solve this issue.

(back to top)

diff --git a/audiotext.spec b/audiotext.spec index 01c07a2..785aef8 100644 --- a/audiotext.spec +++ b/audiotext.spec @@ -5,12 +5,12 @@ block_cipher = None a = Analysis( - ['ROOT DIRECTORY PATH\\audiotext\\src\\main.py'], + ['src/main.py'], pathex=[], binaries=[], datas=[ - ('PATH TO CUSTOMTKINTER', 'customtkinter/'), - ('PATH TO RES FOLDER', 'res/') + ('/opt/homebrew/lib/python3.10/site-packages/customtkinter', 'customtkinter/'), + ('res', 'res/') ], hiddenimports=[], hookspath=[], @@ -40,7 +40,7 @@ exe = EXE( target_arch=None, codesign_identity=None, entitlements_file=None, - icon=['ROOT DIRECTORY PATH\\audiotext\\res\\img\\icon.ico'], + icon=['res/img/icon.ico'], ) coll = COLLECT( exe, diff --git a/src/constants.py b/src/constants.py index 86a8325..4a2ea27 100644 --- a/src/constants.py +++ b/src/constants.py @@ -1,4 +1,4 @@ -LANGUAGES = { +AUDIO_LANGUAGES = { "af": "Afrikaans", "am": "አማርኛ", "ar": "العربية", @@ -28,7 +28,8 @@ "de": "Deutsch", "de_CH": "Schweizer Hochdeutsch", "el": "Ελληνικά", - "en": "English (United States)", + "en": "English", + "en_US": "English (United States)", "en_AU": "English (Australia)", "en_CA": "English (Canada)", "en_GB": "English (United Kingdom)", @@ -105,6 +106,7 @@ "pl": "Polski", "pt_BR": "Português (Brasil)", "pt_PT": "Português (Portugal)", + "pt": "Português", "ro": "Română", "ru": "Русский", "si": "සිංහල", @@ -135,6 +137,11 @@ "zu": "Isizulu", } +APP_LANGUAGES = { + "en": "English", + "es": "Español" +} + FILE = "file" MIC = "mic" diff --git a/src/main.py b/src/main.py index c22c711..381c6a1 100644 --- a/src/main.py +++ b/src/main.py @@ -5,8 +5,8 @@ import constants as c import customtkinter -import logic as lgc import utils as u +import logic as lgc class App(customtkinter.CTk): @@ -56,10 +56,10 @@ def create_sidebar(self): self.lbl_audio_language.grid(row=1, column=0, padx=20, pady=(20, 0)) self.cbx_audio_language = customtkinter.CTkComboBox( - self.frm_sidebar, values=list(c.LANGUAGES.values()) + self.frm_sidebar, values=list(c.AUDIO_LANGUAGES.values()) ) self.cbx_audio_language.grid(row=2, column=0, padx=20, pady=10) - self.cbx_audio_language.set(c.LANGUAGES[locale.getdefaultlocale()[0]]) + self.cbx_audio_language.set(c.AUDIO_LANGUAGES[locale.getlocale()[0]]) # Select file button self.btn_select_file = customtkinter.CTkButton( @@ -93,11 +93,13 @@ def create_sidebar(self): self.omn_app_language = customtkinter.CTkOptionMenu( self.frm_sidebar, - values=[c.LANGUAGES["es"], c.LANGUAGES["en"]], + values=list(c.APP_LANGUAGES.values()), command=self.change_app_language, ) self.omn_app_language.grid(row=8, column=0, padx=20, pady=10) - self.omn_app_language.set(c.LANGUAGES[locale.getdefaultlocale()[0]]) + self.omn_app_language.set( + c.APP_LANGUAGES.get(locale.getlocale()[0].split("_")[0], "English") + ) # Appearance mode self.lbl_appearance_mode = customtkinter.CTkLabel( @@ -113,7 +115,7 @@ def create_sidebar(self): self.omn_appearance_mode.grid(row=10, column=0, padx=20, pady=10) def change_app_language(self, language_name): - language_code = [i for i in c.LANGUAGES if c.LANGUAGES[i] == language_name][0] + language_code = [i for i in c.AUDIO_LANGUAGES if c.AUDIO_LANGUAGES[i] == language_name][0] u.load_translation(language_code) self.lbl_audio_language.configure(text=f'{u._("Audio language")}:') @@ -207,7 +209,7 @@ async def async_get_transcription(self, source): # Get the selected language code language_code = [ key - for key, value in c.LANGUAGES.items() + for key, value in c.AUDIO_LANGUAGES.items() if value.lower() == self.cbx_audio_language.get().strip().lower() ][0] diff --git a/src/utils.py b/src/utils.py index 0e1b3fd..13393b6 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,6 +1,7 @@ import gettext import locale import sys +import constants as c from pathlib import Path @@ -39,10 +40,19 @@ def load_translation(language_code: str): :param str language_code: The code for the language to be used for translation. """ + try: + lang_code_without_territory = language_code.split("_")[0] + if lang_code_without_territory not in c.APP_LANGUAGES: + lang_code_without_territory = "en" + except Exception: + lang_code_without_territory = "en" + locale.setlocale(locale.LC_ALL, "en_US") + + translation = gettext.translation( "all", localedir=ROOT_PATH / "res/locales", - languages=[language_code], + languages=[lang_code_without_territory], fallback=True, ) translation.install() @@ -50,4 +60,4 @@ def load_translation(language_code: str): _ = translation.gettext -load_translation(locale.getdefaultlocale()[0]) +load_translation(locale.getlocale()[0])