Code Monkey home page Code Monkey logo

botbahlul / pyvosklivesubtitle Goto Github PK

View Code? Open in Web Editor NEW
25.0 3.0 5.0 21.25 MB

PySimpleGUI based DESKTOP APP that can RECOGNIZE any live streaming in 23 languages that supported by VOSK then TRANSLATE (using unofficial online Google Translate API) and display it as LIVE CAPTION / LIVE SUBTITLE

License: MIT License

Python 99.36% Shell 0.43% Batchfile 0.21%
google-translate-api live-subtitle python speech-recognition voice-recognition vosk auto-caption live-caption caption pysimplegui

pyvosklivesubtitle's Introduction

pyvosklivesubtitle

PySimpleGUI based DESKTOP APP that can RECOGNIZE any LIVE STREAMING in 23 languages that supported by VOSK then TRANSLATE (using unofficial online Google Translate API) and display it as LIVE CAPTION / LIVE SUBTITLE

pyvosklivesubtitle-0.1.13.mp4

The speech recognition part is using vosk python module https://pypi.org/project/vosk/

pip install --upgrade vosk

On the older versions (bellow 0.0.11) the translation part is using googletrans=4.0.04c1 and pygoogletranslation module https://github.com/Saravananslb/py-googletranslation, but since version 0.0.11 I decide to use my own simple translate function.

The GUI part is using pysimplegui https://github.com/PySimpleGUI/PySimpleGUI

pip install --upgrade pysimplegui

Installation

pip install --upgrade pyvosklivesubtitle

then you can run it by just type :

pyvosklivesubtitle

If you don't have python on your OS you can try compiled version from this release page assets.

If it doesn't run well then you need to install python on your Windows system.

When you run this app for the very first time it may takes some times to download vosk language model, you can check those downloaded models in "/home/username/.cache/vosk" (if you're on Linux) and "C:\Users\Username\.cache\vosk\" (if you're on Windows).

You can always download those small models manually from https://alphacephei.com/vosk/models then extract them to that used folder.

You can try to compile that script in win folder (if your OS is Windows) or linux folder (if your OS is Linux) into a single executable file with pyinstaller:

pip install pyinstaller
pyinstaller --onefile pyvls.py

The executable compiled file will be placed by pyinstaller into dist subfolder of your current working folder, then you can just put that compiled exe file into a folder that has been added to your PATH ENVIRONTMENT so you can execute it from anywhere.

NOTES :

START FROM VERSION 0.1.2 THIS APP USE streamlink MODULE WHICH SUPPORTS urllib3 >= 1.26, < 3.x BRANCH, SO IF YOU'RE STILL WANT TO INSTALL THIS APP TRY TO REINSTALL streamlink WITH --force-reinstall ARGUMENT.

pip install streamlink --force-reinstall

START FROM VERSION 0.1.2 YOU SHOULD USE THAT "mypyinstaller.bat" (or "mypyinstaller.sh" IF YOU'RE ON LINUX) TO COMPILE WITH pyinstaller.

THAT "streamlink" MODULE FOLDER MUST BE ON SAME FOLDER WITH "pyvls.pyw" and "mypyinstaller.bat", OR YOU CAN CHANGE THE LOCATION FOLDER BY EDITING "mypyinstaller.bat".

DONT FORGET TO PLACE THOSE LIBS FILES FROM VOSK (libgcc_s_seh-1.dll, libstdc++-6.dll, libvosk.dll, & libwinpthread-1.dll if your OS is Windows, libvosk.so if your OS is Linux) INTO SAME FOLDER WITH COMPILED EXE FILE!

ALSO NOTE THAT SINCE VERSION 0.1.2 THIS APP NEED ffmpeg AND ffprobe, you can get it from https://www.ffmpeg.org/

IN DEBIAN BASED LINUX OS YOU CAN INSTALL IT WITH :

sudo apt update
sudo apt install -y ffmpeg

I was succesfuly compiled this script in Windows 10 with pyinstaller-5.1 and Pyhton-3.10.4, and python-3.8.12 in Debian 9

Another alternative way you can install this script with python by cloning this git (or downloading this git as zip then extract it into a folder), and then just type :

python setup.py build
python setup.py install

If you fail when installing any python modules using pip, you can always use this way, get that module from github then build them manually

For best recognizing performance, on windows you will need STEREO MIX or VIRTUAL AUDIO CABLE as RECORDING/INPUT DEVICE image image image

LAUNCH Audio Repeater MME, NOT Audio Repeater KS! AND THEN CLICK THAT START BUTTON AND MINIMIZE IT, DON'T CLOSE IT!

image

and on linux you willl need PAVUCONTROL (by choosing MONITOR of your audio device as INPUT DEVICE) image image

To DRAG/MOVE that TRANSLATION TEXT anywhere on the screen, just USE CONTROL KEY + LEFT MOUSE combination.

ANOTHER NOTES, DON'T FORGET TO CHANGE YOUR CONSOLE (COMMAND PROMPT WINDOW) CODE PAGE TO 65001 (UTF-8)!

To change the codepage for the console, do the following:

Start -> Run -> regedit
Go to [HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\Autorun]
Change the value to @chcp 65001>nul
If Autorun is not present, you can add a New String

image

Usage

usage: pyvosklivesubtitle [-h] [-S SRC_LANGUAGE] [-D DST_LANGUAGE] [-lls] [-lld] [-sf SUBTITLE_FILENAME] [-F SUBTITLE_FORMAT] [-lsf]
                          [-ld] [-af AUDIO_FILENAME] [-d DEVICE] [-r SAMPLERATE] [-u URL] [-vf VIDEO_FILENAME] [-v]

options:
  -h, --help            show this help message and exit
  -S SRC_LANGUAGE, --src-language SRC_LANGUAGE
                        Spoken language
  -D DST_LANGUAGE, --dst-language DST_LANGUAGE
                        Desired language for translation
  -lls, --list-src-languages
                        List all available source languages
  -lld, --list-dst-languages
                        List all available destination languages
  -sf SUBTITLE_FILENAME, --subtitle-filename SUBTITLE_FILENAME
                        Subtitle file name for saved transcriptions
  -F SUBTITLE_FORMAT, --subtitle-format SUBTITLE_FORMAT
                        Desired subtitle format for saved transcriptions (default is "srt")
  -lsf, --list-subtitle-formats
                        List all available subtitle formats
  -ld, --list-devices   show list of audio devices and exit
  -af AUDIO_FILENAME, --audio-filename AUDIO_FILENAME
                        audio file to store recording to
  -d DEVICE, --device DEVICE
                        input device (numeric ID or substring)
  -r SAMPLERATE, --samplerate SAMPLERATE
                        sampling rate in Hertz for example 8000, 16000, 44100, or 48000
  -u URL, --url URL     URL of live streaming if you want to record the streaming
  -vf VIDEO_FILENAME, --video-filename VIDEO_FILENAME
                        video file to store recording to
  -v, --version         show program's version number and exit

Those command line switches are just to make this application directly select the language in combo box, so it's okay if you don't use them

License

MIT

Check my other SPEECH RECOGNITIION + TRANSLATE PROJECTS https://github.com/botbahlul?tab=repositories

Buy me coffee : https://sociabuzz.com/botbahlul/tribe

pyvosklivesubtitle's People

Contributors

botbahlul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pyvosklivesubtitle's Issues

Doesn't work using Python 3.10.4 - 64 bits, and Win 10. Please help me :)

I tried many things to fix it, first with Py 11, Py 3.8.3. Currently on Py 3.10.4.
Capture d’écran 2023-05-31 204341
I tried to install by pip because i have mistakes with last compiled version (and the two previous versions too). In the folder, this is the 0.1.14 compiled and clone version of Git repository.

merged-with-compilated
merged-with-compilated-2

Then, the error with the .pyw file :
IDLE-Shell-3-10-4

With command prompt, successfully installed with Py 3.10.4 but error with main_window (I already installed manual languages .cache\vosk and ffmpeg in system32) :

cmd-installed
cmd-error

charmap encoding issue

when trying to use russian

log

Traceback (most recent call last):
File "", line 198, in run_module_as_main
File "", line 88, in run_code
File "D:\Scripts\pyvosklivesubtitle.exe_main
.py", line 7, in
File "D:\Lib\site-packages\pyvosklivesubtitle_init
.py", line 3982, in main
partial_result_file.write(text)
File "D:\Lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-3: character maps to

[Feature]Very good project, hope to support more features

For example
memorized pre-selected language options (need to reselect language each time you start the program)
History transcription
Save transcriptions as text
Caption hover window with movable position
Thank you for your work.

win11

The executable file compiled on Win11 reports an error and cannot be run

Error on Windows10

Hi, I tried to install your application and ran into below error, could you pls help when convenient? Thanks.

C:\Users\Administrator\Documents\GitHub\pyvosklivesubtitle>pyvosklivesubtitle
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pyvosklivesubtitle_init_.py", line 2138, in stop_ffmpeg_windows
tasklist_output = subprocess.check_output(['tasklist'], creationflags=subprocess.CREATE_NO_WINDOW).decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 4: invalid continuation byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in run_module_as_main
return run_code(code, main_globals, None,
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in run_code
exec(code, run_globals)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\Scripts\pyvosklivesubtitle.exe_main
.py", line 7, in
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pyvosklivesubtitle_init
.py", line 3258, in main
stop_ffmpeg_windows(error_messages_callback=show_error_messages)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pyvosklivesubtitle_init
.py", line 2157, in stop_ffmpeg_windows
error_messages_callback(e)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\pyvosklivesubtitle_init_.py", line 3050, in show_error_messages
main_window.write_event_value("-EXCEPTION-", messages)
NameError: name 'main_window' is not defined

C:\Users\Administrator\Documents\GitHub\pyvosklivesubtitle>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.