Skip to content

Commit

Permalink
Fixed Mac issues
Browse files Browse the repository at this point in the history
  • Loading branch information
José Carlos López committed Feb 6, 2023
1 parent 97750ff commit db4cb33
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<p align="right">(<a href="#top">back to top</a>)</p>
Expand All @@ -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.
Expand All @@ -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.

<p align="right">(<a href="#top">back to top</a>)</p>

Expand Down
8 changes: 4 additions & 4 deletions audiotext.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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=[],
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions src/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LANGUAGES = {
AUDIO_LANGUAGES = {
"af": "Afrikaans",
"am": "አማርኛ",
"ar": "العربية",
Expand Down Expand Up @@ -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)",
Expand Down Expand Up @@ -105,6 +106,7 @@
"pl": "Polski",
"pt_BR": "Português (Brasil)",
"pt_PT": "Português (Portugal)",
"pt": "Português",
"ro": "Română",
"ru": "Русский",
"si": "සිංහල",
Expand Down Expand Up @@ -135,6 +137,11 @@
"zu": "Isizulu",
}

APP_LANGUAGES = {
"en": "English",
"es": "Español"
}

FILE = "file"
MIC = "mic"

Expand Down
16 changes: 9 additions & 7 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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")}:')
Expand Down Expand Up @@ -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]

Expand Down
14 changes: 12 additions & 2 deletions src/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import gettext
import locale
import sys
import constants as c
from pathlib import Path


Expand Down Expand Up @@ -39,15 +40,24 @@ 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()
global _
_ = translation.gettext


load_translation(locale.getdefaultlocale()[0])
load_translation(locale.getlocale()[0])

0 comments on commit db4cb33

Please sign in to comment.