Skip to content

Development

Fauzan F A edited this page Dec 17, 2023 · 20 revisions

This app is developed using python version 3.11.6 but it should work with python 3.8+

πŸ‘€ Starting Development

For development, you might need to have Build tools for Visual Studio installed

  1. Clone the repo with its submodules by running git clone --recurse-submodules https://github.com/Dadangdut33/Speech-Translate.git
  2. Cd into the project directory
  3. Create a virtual environment by running python -m venv venv
  4. Activate your virtual environment
  5. Install all the dependencies needed by running pip install -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cu118 if you are using GPU or pip install -r requirements.txt if you are using CPU.
  6. You should be ready now πŸ‘

Notes:

  • If you forgot the --recure-submodules flag when cloning the repository, you can do git submodule update --init --recursive in the project directory to pull the needed submodules.
  • The --extra-index-url is needed to install CUDA version of pytorch and for this one we are using CUDA 11.8. If your device is not compatible or you need to use other version of CUDA you can check the previous pytorch version in this link or this.

πŸƒβ€β™‚οΈ Running the app

You can run the app by running the Run.py located in root directory with the command python Run.py. Alternatively you can also run it using python -m speech_translate in the root directory.

πŸ› οΈ Building

Before compiling the project, make sure you have installed all the dependencies and setup your pytorch correctly. Your pytorch version will control wether the app will use GPU or CPU (that's why it's recommended to make virtual environment for the project).

The pre compiled version in this project is built using cx_freeze, we have provided the script in build.py. This build script is only configured for windows build at the moment, but feel free to contribute if you know how to build properly for other OS.

To compile it into an exe run python build.py build_exe in the root directory. This will produce a folder containing the compiled project alongside an executable in the build directory. After that, use innosetup script to create an installer. You can use the provided installer.iss to create the installer.

🧹 Linter - Formatter

I use vscode with the pylance and isort for the formatter of this project. The linter is provided using pylint. There is a config for it in the .vscode folder

πŸ“‚ Architecture

The architecture of the code is fairly simple with the code located inside the speech_translate folder. The files and folder inside can be explained like this:

Run.py
β”‚
β”œβ”€β”€ πŸ—€ assets/         -> folder to store assets of the app
β”‚   └── ...
β”œβ”€β”€ πŸ—€ theme/          -> folder to store theme of the app
β”‚   └── ...
β”œβ”€β”€ πŸ—€ ui/             -> location of code for the UI of the app
β”‚   └── ...
β”œβ”€β”€ πŸ—€ utils/          -> location of code for the utility function of the app
β”‚   └── ...
β”œβ”€β”€ __main__.py        -> script to run the app in here along with some patches
β”œβ”€β”€ _constants.py      -> constants variable
β”œβ”€β”€ _logging.py        -> logger setup
β”œβ”€β”€ _path.py           -> path/location needed for the app
β”œβ”€β”€ _version.py        -> app and setting version
└── linker.py          -> containing bridge class to get around circular import, also have the setting json class instantiated here

πŸ–ΌοΈ GUI & Theming

The GUI of the app is made using tkinter, a very simple gui library. For the theme, we took advantage of sunvalley ttk theme made by rdbende. You can probably use other works made by rdbende if you want to add other themes.

❓ linker.py

To communicate with the other units of the code, we use linker.py, in there we instantiate BridgeClass as bc and then use it to store reference to other class needed in the app. I know that there are other ways to do it but i think this one works just fine.

❓ The starting script

The main code to start the app is located at speech_translate/__main__.py. In here we do some monkey patching and set environment for some of the library used in the app. After that we call the main function in speech_translate/ui/window/main.py to start the app.

Compatibility

This project should be compatible with Windows and other platforms. But I only tested it extensively on Windows. If you find any bugs or issues, feel free to create an issue.

Clone this wiki locally