Skip to content

Commit 4f426a9

Browse files
authored
Squashed commit of the following: (#1177)
commit 3bd614e Merge: c8b662b 094c388 Author: ReimarBauer <rb.proj@gmail.com> Date: Mon Aug 23 16:35:23 2021 +0200 Merge pull request #1170 from risehr/textfiles Added text files for kml, mscolab, wms, and views tutorials. commit 094c388 Author: Hrithik Kumar Verma <vermahrithik812@gmail.com> Date: Mon Aug 23 19:21:46 2021 +0530 Corrected spelling of MSColab commit 83551be Author: Hrithik Kumar Verma <vermahrithik812@gmail.com> Date: Mon Aug 23 17:35:37 2021 +0530 Added text files for kml, mscolab, wms, and views tutorials and fixed typos in tutorials.rst file commit c8b662b Merge: ee98974 3937b0a Author: ReimarBauer <rb.proj@gmail.com> Date: Mon Aug 23 07:41:44 2021 +0200 Merge pull request #1166 from risehr/documentation Created the tutorials.rst file commit 3937b0a Author: Hrithik Kumar Verma <vermahrithik812@gmail.com> Date: Mon Aug 23 02:32:17 2021 +0530 Fixed typos in performance settings text file commit 156fa36 Author: Hrithik Kumar Verma <vermahrithik812@gmail.com> Date: Mon Aug 23 02:22:41 2021 +0530 Added performance settings text file in tutorials/textfiles commit 6acc89e Author: Hrithik Kumar Verma <vermahrithik812@gmail.com> Date: Mon Aug 23 01:49:05 2021 +0530 Fixed typos in text files commit f681c0f Author: Hrithik Kumar Verma <vermahrithik812@gmail.com> Date: Mon Aug 23 01:18:54 2021 +0530 Updated tutorials.rst file and added some text files commit 0417b04 Author: Hrithik Kumar Verma <vermahrithik812@gmail.com> Date: Mon Aug 23 00:29:08 2021 +0530 Created the tutorials.rst file commit ee98974 Author: Hrithik Kumar Verma <54763705+risehr@users.noreply.github.com> Date: Sat Aug 21 13:59:43 2021 +0530 Mscolab tutorial, TTS feature for audios (#1162) * mscolab tutorial created * Created mscolab tutorial and added text to audio conversion feature for audio of the tutorial videos. Also updated tutorials.txt requirement file * Made some minor code improvements and rectified spelling mistakes * Made audio.py more customizable in terms of which translation and speech conversion APIs are to be used and also updated tutorials.txt requirement file * Removed the unnecessary comments commit df9aa18 Author: Hrithik Kumar Verma <54763705+risehr@users.noreply.github.com> Date: Tue Aug 17 14:11:38 2021 +0530 KML overlay, Hexagon Control, Performance settings tutorial completed (#1144) * Kml, hexagon control, and performance settings tutorial completed * Improved the screenrecorder class fixing some bugs, improved restricted size recording of windows * Minor changes in screen recorder class * made small changes in the header files of scipt and other minor changes in hexagon tutorial * Made the code more efficient by small changes in hexagon control tutorial commit bd3f251 Author: Hrithik Kumar Verma <54763705+risehr@users.noreply.github.com> Date: Mon Aug 9 18:55:26 2021 +0530 Remote Sensing and Satellite Track Tutorial (#1136) * Tutorial for remote sensing and satellite track and flexible/changeable screen recording area * Enabled FailSafe from screenrecorder.py file commit 5f70c3a Merge: 9170617 769b98a Author: ReimarBauer <rb.proj@gmail.com> Date: Fri Aug 6 16:58:51 2021 +0200 Merge pull request #1140 from Open-MSS/merged_develop_to_GSOC2021-HrithikKumarVerma Merged develop to gsoc2021 hrithik kumar verma commit 769b98a Author: ReimarBauer <rb.proj@gmail.com> Date: Fri Aug 6 16:25:42 2021 +0200 merge mistake fixed commit 7fd3765 Merge: 9170617 492482f Author: ReimarBauer <rb.proj@gmail.com> Date: Fri Aug 6 16:16:53 2021 +0200 Merge branch 'develop' into GSOC2021-HrithikKumarVerma commit 9170617 Merge: 6ab5a9d 36834c2 Author: ReimarBauer <rb.proj@gmail.com> Date: Wed Aug 4 09:28:13 2021 +0200 Merge pull request #1104 from risehr/views_tutorial [Completed] Automated tutorial for how to create a project in MSS using all the views. commit 36834c2 Author: Hrithik Kumar Verma <vermahrithik812@gmail.com> Date: Sun Aug 1 00:54:27 2021 +0530 Rectified some small mistakes such as remove extra space and unnecessary comments commit 41e83e1 Author: Hrithik Kumar Verma <vermahrithik812@gmail.com> Date: Sat Jul 31 02:51:43 2021 +0530 Made tutorial_views.py script to work for linux smoothly commit 0fee992 Author: Hrithik Kumar Verma <vermahrithik812@gmail.com> Date: Wed Jul 28 16:09:08 2021 +0530 Automated tutorial for how to create a project in MSS using all the views commit 6ab5a9d Author: Hrithik Kumar Verma <54763705+risehr@users.noreply.github.com> Date: Sun Jul 18 10:57:40 2021 +0530 Wms tutorial (#1083) * Made cursor visible and finished wms automated tutorial * flake8 corrections * Improved code for use in Linux systems.(It was working well in other systems) * Changed header file for the python scripts in mss/tutorials/* commit 3bb422c Merge: 2eda795 84ef56d Author: ReimarBauer <rb.proj@gmail.com> Date: Wed Jul 7 12:02:14 2021 +0200 Merge pull request #1074 from risehr/waypoints_tutorial Waypoints Tutorial : Working on Linux system now. commit 84ef56d Author: Hrithik Kumar Verma <vermahrithik812@gmail.com> Date: Mon Jul 5 21:08:40 2021 +0530 Rectified logical error in if statement; improved code to run both on linux and windows system efficiently commit 89d1417 Author: Hrithik Kumar Verma <vermahrithik812@gmail.com> Date: Mon Jul 5 18:45:50 2021 +0530 Modified waypoints tutorial to make it run smoothly on linux systems commit 2eda795 Author: Hrithik Kumar Verma <54763705+risehr@users.noreply.github.com> Date: Fri Jul 2 14:24:53 2021 +0530 Completed the waypoints tutorial and resolved the screen recording problems of being played too fast (#1067) * Allow specification of file for linear defaultstyle (#1028) * Allow specification of file for default * Simplify if condition * Increase coverage (#1020) * Add wms_control tests * Add more mscolab tests * Add mpl_qtwidget coverage * Add mss_pyui coverage * Add transparency, noframe and xml checks * Add more wms tests * Test import with plugins * Add linearview tests * Add more multilayering tests * Revert to old testing.yml * Leave no dangling windows * Remove todo, move ConnectionError to bottom Co-authored-by: ReimarBauer <rb.proj@gmail.com> * Migrate existing thermodynamic functions to metpy functions (#1009) * removed functions from thermolib.py functions to be replaced by metpy were removed * fixed: flake8 * fixed: flake8 * migrated to metpy functions Co-Authored-By: J. Ungermann <28449201+joernu76@users.noreply.github.com> * Fixed: flake8 * Fixed: flake8 * Fixed tests * Fixed: flake8 * Fixed: failing tests * Ficed: tests * Units discarded upon returning results Co-Authored-By: J. Ungermann <28449201+joernu76@users.noreply.github.com> * `omega_to_w` migrated to metpy Co-authored-by: ReimarBauer <rb.proj@gmail.com> Co-authored-by: J. Ungermann <28449201+joernu76@users.noreply.github.com> * updated documentation (#1008) * updated documentation * improved install/update procedure Co-authored-by: Reimar Bauer <rb.proj@gmail.com> * Fixed: #999 (#1010) * .format replaced with f" string * updated copyright year * fixes #1014 (#1015) * Remove Qt imports (#1019) * Fixes #1014 changing http to https (#1017) Co-authored-by: ReimarBauer <rb.proj@gmail.com> * Linear view mscolab bug (#1021) * fixed tableview not opening bug; added test * added raising of mscolab window after closing view * preparation of v4.0.1 (#1023) * preparation of v4.0.1 * updated install instruction Co-authored-by: J. Ungermann <j.ungermann@fz-juelich.de> * Fix pyproj 3.1.0 error (#1033) * Made a screen recorder and automated tutorial for demonstrating use of waypoints * Renamed tut pictures to just pictures and moved the tutorials.txt to requirements.d * Minor bug fixes. (#1054) * Return proper unit for eq. potential temperature (degC->K) * Do not assume units of pressure levels for several old plotting styles. * Fix values of geopotential altitude in demodata * issue #719 solved (#729) * issue #719 solved * updated development.rst * updated development.rst Co-authored-by: ReimarBauer <rb.proj@gmail.com> * Select newest init-time and carry over multilayering (#1047) Co-authored-by: J. Ungermann <j.ungermann@fz-juelich.de> * Fix some issues with elevation caching and model level dimensions. (#1061) Fix #1066 * Added missing filename key. (#1062) See #1066 * Waypoints tutorial completed * Just changed the sleep timings of the code to make it more efficient : tutorial_waypoints.py * Added the updated tutorials.txt in requirements.d Co-authored-by: May <baermay98@gmail.com> Co-authored-by: ReimarBauer <rb.proj@gmail.com> Co-authored-by: Jatin Jain <72596619+Jatin2020-24@users.noreply.github.com> Co-authored-by: J. Ungermann <28449201+joernu76@users.noreply.github.com> Co-authored-by: open-mss-build <77272604+open-mss-build@users.noreply.github.com> Co-authored-by: Aryan Gupta <42470695+withoutwaxaryan@users.noreply.github.com> Co-authored-by: Aravind Murali <aravindmurali711@gmail.com> Co-authored-by: J. Ungermann <j.ungermann@fz-juelich.de> Co-authored-by: Archishman Sengupta <71402528+ArchishmanSengupta@users.noreply.github.com> commit fca444a Author: Hrithik Kumar Verma <54763705+risehr@users.noreply.github.com> Date: Thu Jul 1 14:49:02 2021 +0530 Syncing my GSOC branch with develop (#1066) * Allow specification of file for linear defaultstyle (#1028) * Allow specification of file for default * Simplify if condition * Increase coverage (#1020) * Add wms_control tests * Add more mscolab tests * Add mpl_qtwidget coverage * Add mss_pyui coverage * Add transparency, noframe and xml checks * Add more wms tests * Test import with plugins * Add linearview tests * Add more multilayering tests * Revert to old testing.yml * Leave no dangling windows * Remove todo, move ConnectionError to bottom Co-authored-by: ReimarBauer <rb.proj@gmail.com> * Migrate existing thermodynamic functions to metpy functions (#1009) * removed functions from thermolib.py functions to be replaced by metpy were removed * fixed: flake8 * fixed: flake8 * migrated to metpy functions Co-Authored-By: J. Ungermann <28449201+joernu76@users.noreply.github.com> * Fixed: flake8 * Fixed: flake8 * Fixed tests * Fixed: flake8 * Fixed: failing tests * Ficed: tests * Units discarded upon returning results Co-Authored-By: J. Ungermann <28449201+joernu76@users.noreply.github.com> * `omega_to_w` migrated to metpy Co-authored-by: ReimarBauer <rb.proj@gmail.com> Co-authored-by: J. Ungermann <28449201+joernu76@users.noreply.github.com> * updated documentation (#1008) * updated documentation * improved install/update procedure Co-authored-by: Reimar Bauer <rb.proj@gmail.com> * Fixed: #999 (#1010) * .format replaced with f" string * updated copyright year * fixes #1014 (#1015) * Remove Qt imports (#1019) * Fixes #1014 changing http to https (#1017) Co-authored-by: ReimarBauer <rb.proj@gmail.com> * Linear view mscolab bug (#1021) * fixed tableview not opening bug; added test * added raising of mscolab window after closing view * preparation of v4.0.1 (#1023) * preparation of v4.0.1 * updated install instruction Co-authored-by: J. Ungermann <j.ungermann@fz-juelich.de> * Fix pyproj 3.1.0 error (#1033) * Minor bug fixes. (#1054) * Return proper unit for eq. potential temperature (degC->K) * Do not assume units of pressure levels for several old plotting styles. * Fix values of geopotential altitude in demodata * issue #719 solved (#729) * issue #719 solved * updated development.rst * updated development.rst Co-authored-by: ReimarBauer <rb.proj@gmail.com> * Select newest init-time and carry over multilayering (#1047) Co-authored-by: J. Ungermann <j.ungermann@fz-juelich.de> * Fix some issues with elevation caching and model level dimensions. (#1061) Fix #1066 * Added missing filename key. (#1062) See #1066 Co-authored-by: May <baermay98@gmail.com> Co-authored-by: ReimarBauer <rb.proj@gmail.com> Co-authored-by: Jatin Jain <72596619+Jatin2020-24@users.noreply.github.com> Co-authored-by: J. Ungermann <28449201+joernu76@users.noreply.github.com> Co-authored-by: open-mss-build <77272604+open-mss-build@users.noreply.github.com> Co-authored-by: Aryan Gupta <42470695+withoutwaxaryan@users.noreply.github.com> Co-authored-by: Aravind Murali <aravindmurali711@gmail.com> Co-authored-by: J. Ungermann <j.ungermann@fz-juelich.de> Co-authored-by: Archishman Sengupta <71402528+ArchishmanSengupta@users.noreply.github.com>
1 parent 029089e commit 4f426a9

File tree

146 files changed

+5395
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+5395
-2
lines changed

docs/components.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ Components
88
deployment
99
mscolab
1010
demodata
11+
tutorials
1112

1213

docs/development.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.. _development:
22

3-
===========
43
Development
54
===========
65

@@ -134,6 +133,7 @@ Installing dependencies
134133

135134
MSS is based on the software of the conda-forge channel located, so we have to add this channel to the default::
136135

136+
137137
$ conda config --add channels conda-forge
138138

139139
Your content of the .condarc config file should have conda-forge on top::

docs/samples/config/mss/performance_simple.json.sample renamed to docs/samples/config/mss/performance_simple.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"_comment2": "takeoff_weight: maximum weight for takeoff (lbs)",
1111
"_comment3": "empty_weight: aircraft weight without fuel (lbs)",
1212
"_comment4": "climb/descent: weight(lbs), altitude(ft), duration(min), distance(nm), fuel(lbs)",
13-
"_comment5": "cruise: weight(lbs), altitude(ft), total air speed(nm/h), fuel flow(lbs/h)"
13+
"_comment5": "cruise: weight(lbs), altitude(ft), total air speed(nm/h), fuel flow(lbs/h)",
1414
"_comment6": "ceiling: polynomial coeficients for relating weight (lbs) with peak flightlevel (hft). Leftmost coefficient is the intercept."
1515
}

docs/tutorials.rst

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
==============================================================================
2+
A user guide for tool chain of automated tutorials for the MSUI user interface
3+
==============================================================================
4+
5+
The tool chain for tutorials are automatically generated tutorials by use of python scripts to automate the software to
6+
perform different tasks and hence, demonstrating and explaining to the user various parts of the MSS software. It tells
7+
the user about the different technical aspects of MSS which a new user would take time to know that, otherwise.
8+
9+
There are nine such total automating scripts that are meant for explaining nine such parts or sub parts of MSS software
10+
and it's use.
11+
Listing them below as:
12+
13+
* tutorial_hexagoncontrol.py for explaining hexagon control in table view.
14+
15+
* tutorial_kml.py for explaining kml dockwidget in topview.
16+
17+
* tutorial_mscolab.py for understanding mscolab feature of MSS.
18+
19+
* tutorial_performancesettings.py for giving a demo what is there in performance settings of table view.
20+
21+
* tutorial_remotesensing.py for demonstrating remote sensing dockwidget of topview.
22+
23+
* tutorial_satellitetrack.py for demonstrating satellite track dockwidget of topview.
24+
25+
* tutorial_views.py for demonstrating the top view, sideview, table view and linear view together.
26+
27+
* tutorial_waypoints.py for demonstrating how to place waypoints in topview.
28+
29+
* tutorial_wms.py for explaining web map service section of topview.
30+
31+
Other important files with their functions are as follows:
32+
33+
* screenrecorder.py for opening a screen recorder window which is a small window in the top right corner of the
34+
rectangular recording area on the screen. The window gets closed when you press 'q' keeping the window in focus. This
35+
will also stop the recording of the screen when window gets closed.
36+
37+
* cursor.py which is used for generating the image of the present cursor image.
38+
39+
* audio.py which translates and converts into speech the texts and saves them as .mp3 files.
40+
41+
System Requirements
42+
===================
43+
Keep the following things in mind before running a script
44+
45+
* You should have only an **US keyboard layout**. If you have a different keyboard layout, you just need to change it to
46+
US keyboard!
47+
* The **cursor.py** python file will run only on Linux and not on Windows for grabbing the mouse pointer image.
48+
49+
* The screenrecorder.py works only in **Full HD Screens**.
50+
51+
* The screen recording starts as the recording window appears and ends when you quit the recording window by pressing
52+
'q' when the window is being displayed in the foreground.
53+
54+
* The **audio.py** file should have translation APIs and text-to-speech (t2s) APIs written at specified places inside it
55+
to run successfully! It has a #ToDo to read.
56+
57+
58+
Getting Started..
59+
=================
60+
61+
On the Anaconda terminal, type the following ::
62+
63+
cd ..../MSS/$
64+
$ export PYTHONPATH=.../MSS # Path of MSS
65+
$ conda activate mssdev
66+
67+
68+
(mssdev)$ mamba install --file requirements.d/tutorials.txt
69+
(mssdev)$ conda deactivate
70+
(base)$ conda activate mssdev
71+
72+
73+
This will install all the dependencies required for running of the tutorials.
74+
75+
76+
**On Linux additionally** ::
77+
78+
$ sudo apt-get install scrot
79+
$ sudo apt-get install python3-tk
80+
$ sudo apt-get install python3-dev
81+
$ sudo apt-get install libx11-dev libxext-dev libxfixes-dev libxi-dev
82+
83+
84+
Now, just go into the **../MSS/tutorials/** directory ::
85+
86+
$ cd ../MSS/tutorials/
87+
88+
89+
**Note**
90+
91+
You must go into the tutorials directcory and then run the .py files. And always remember to add the PYTHONPATH to
92+
........../MSS/ directory.
93+
You cannot just do like this ::
94+
95+
$ python MSS/tutorials/sreenrecorder.py # This will be problematic.
96+
97+
98+
In Linux for making the cursor visible as a highlighter, perform the following
99+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100+
If you are in Windows, there is no need of this highlighter. It is by default that it also records the mouse-pointer.
101+
102+
* Clone the repository https://github.com/swillner/highlight-pointer.git into a directory eg. `highlighter` on your system
103+
104+
Change directory into that location ::
105+
106+
$ cd highlighter/highlight-pointer/
107+
$ make
108+
109+
After the `make` gets successful, run ::
110+
111+
$ ./highlight-pointer -r 10
112+
113+
This will make your cursor highlighted as a red cursor having radius as 10. You can minimize the terminal and continue
114+
your work with the highlighted cursor.
115+
When you have to stop just open that terminal again and type **CTRL + C**
116+
117+
For more details in its customization, you can visit https://github.com/swillner/highlight-pointer
118+
119+
The Running of the Scripts
120+
~~~~~~~~~~~~~~~~~~~~~~~~~~
121+
Each python file inside MSS/tutorials can be run directly like ::
122+
123+
(mssdev)~/..MSS/tutorials/ $ python screenrecorder.py
124+
125+
For recording anything on your screen. The videos will be then saved to `MSS/tutorials/Screen Recordings/`
126+
127+
For all the tutorials, you can do the same, example ::
128+
129+
(mssdev)~/..MSS/tutorials/ $ python tutorial_remotesensing.py
130+
(mssdev)~/..MSS/tutorials/ $ python tutorial_satellitetrack.py
131+
(mssdev)~/..MSS/tutorials/ $ python tutorial_hexagoncontrol.py
132+
133+
The `MSS/tutorials/textfiles` contain descriptions of the tutorial videos in text format, these later can be
134+
converted to audio files by `audio.py` script after adding certain #ToDOs there.
135+
136+
**Note**
137+
In tutorials development, when creating a class of Screen Recorder as ::
138+
139+
$ rec = ScreenRecorder(x_start, y_start, width, height) or $ rec = ScreenRecorder()
140+
$ rec.capture()
141+
$ rec.stop_capture()
142+
143+
When no arguments are passed to ScreenRecorder class during object creation, it records full screen but if you have to
144+
record a particular area of screen, just pass the below parameters.
145+
146+
* "x_start" is the starting pixel from left or how many pixels from the left panel it will capture the screen area.
147+
* "y_Start" is the starting pixel from top or how many pixels down from the top panel, it will start capture.
148+
* "width" is the pixel length from x_start that will form the recording area.
149+
* "height is the pixel length from y_start that will from the recording area.
150+
151+
The top left corner is (0,0) and the width for eg is 1920 and the height for eg is 1080 of my screen.
152+
153+
Knowing MouseInfo()
154+
~~~~~~~~~~~~~~~~~~~
155+
For deciding the pixels, or know how much length or height i should go down or what is the relative distance of one
156+
point from the other, pyautogui's mouseInfo() comes to the rescue ::
157+
158+
(mssdev)$ python
159+
$ import pyautogui
160+
$ pyautogui.mouseInfo()
161+
162+
This will open a window which will be very helpful in development and other pixel position related things.
163+
164+
.. Important::
165+
MSS/tutorials is still under development, so if the automation makes problems in your system, it may be due to certain
166+
parameters specific to your system and also since it is not widely used and tried, there will be always a scope of
167+
improvement. Kindly report that bug or discrepancies to https://github.com/Open-MSS/MSS/issues/new
168+
169+
Videos post processing via ffmpeg
170+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
171+
The post processing of the videos can be done using ffmpeg in Command Line Interface.
172+
173+
The generated video size is too large, so if you want to reduce the size, you can ::
174+
175+
$ cd MSS/tutorials/Screen Recordings/
176+
(mssdev)$ ffmpeg -i input.mp4 -vcodec h264 -acodec mp2 output.mp4
177+
178+
For trimming the videos from a start (00:14:00) and end time (05:19:00), you can ::
179+
180+
$ cd MSS/tutorials/Screen Recordings/
181+
(mssdev)$ ffmpeg -i input.mp4 -ss 00:14:00 -to 05:19:00 -c:v libx264 -crf 30 output.mp4
182+
183+
For cropping the video
184+
(you can also use Screen Recorder for selected screen area recording feature as described above) ::
185+
186+
$ cd MSS/tutorials/Screen Recordings/
187+
(mssdev)$ fmpeg -i input.mp4 -filter_complex "[0:v]crop=1919:978:0:33[cropped]" -map "[cropped]" output.mp4
188+
189+
# “crop=width:height:x:y” is the format
190+
191+
For merging audios into the video ::
192+
193+
(mssdev)$ ffmpeg -i input.mp4 -i audio.mp3 -c:v copy -c:a aac output.mp4
194+
In this case, the video and audio must be in same directory and you should cd into that directory.

requirements.d/tutorials.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This file may be used to create an environment using:
2+
# $ conda create --name <env> --file <this file>
3+
# platform: linux-64
4+
mouseinfo=0.1.3=pypi_0
5+
opencv=4.5.2=py39hf3d152e_0
6+
playsound=1.3.0=pypi_0
7+
pyautogui=0.9.48=py39hde42818_1
8+
pyscreeze=0.1.27=pyhd8ed1ab_0
9+
python-mss=6.1.0=pyhd3deb0d_0

tutorials/audio.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
"""
2+
mss.tutorials.audio
3+
~~~~~~~~~~~~~~~~~~~
4+
5+
This python script is meant for generating audio of our choice from text files describing the tutorial.
6+
7+
This file is part of mss.
8+
9+
:copyright: Copyright 2021 Hrithik Kumar Verma
10+
:copyright: Copyright 2021 by the mss team, see AUTHORS.
11+
:license: APACHE-2.0, see LICENSE for details.
12+
13+
Licensed under the Apache License, Version 2.0 (the "License");
14+
you may not use this file except in compliance with the License.
15+
You may obtain a copy of the License at
16+
17+
http://www.apache.org/licenses/LICENSE-2.0
18+
19+
Unless required by applicable law or agreed to in writing, software
20+
distributed under the License is distributed on an "AS IS" BASIS,
21+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22+
See the License for the specific language governing permissions and
23+
limitations under the License.
24+
"""
25+
import os
26+
import time
27+
import playsound
28+
from glob import glob
29+
30+
# ToDo We have to add translation services
31+
# e.g. https://cloud.google.com/translate/docs, https://www.deepl.com/pro?cta=menu-plans/
32+
33+
"""
34+
Please import here, the modules you need for text translations (tt) and text-to-speech conversions (t2s).
35+
Example:
36+
import xyz as tt # For translating text
37+
from zyx import abc as t2s # For converting text to speech
38+
"""
39+
# xyz don't add credential of API keys here, this has to be done later as secret for a CI call
40+
41+
42+
class TutorialAudio:
43+
"""
44+
This is the audio class for storing audio files and playing them.
45+
"""
46+
def __init__(self):
47+
"""
48+
The constructor sets the translator object and audio path for storing the audios.
49+
"""
50+
# Use here instead of None the function of the translator for eg tt.Translator()
51+
self.translate = None
52+
self.audio_path = os.path.join(os.getcwd(), "Audio Files")
53+
os.makedirs(self.audio_path, exist_ok=True)
54+
55+
def translate_text(self, input_text, input_lang, output_lang):
56+
"""
57+
This function is used to translate texts packets in the output language passed to the function.
58+
"""
59+
txt = self.translate.translate(input_text, src=input_lang, dest=output_lang)
60+
return txt.text
61+
62+
def text_to_audio(self, source_lang, destination_lang):
63+
"""
64+
This function is used to convert text file into speech of selected choice passed as parameter and store the
65+
audio files and playing them. It converts all text files one by one present in the "tutorials/textfiles" folder.
66+
"""
67+
for f in glob("textfiles/*.txt"):
68+
print(f"\nINFO : Please wait, the text file {f} is being converted to audio file...\n")
69+
with open(f) as file:
70+
source_text = file.read()
71+
if source_lang == destination_lang:
72+
destination_text = source_text
73+
else:
74+
destination_text = self.translate_text(source_text, source_lang, destination_lang)
75+
print(destination_text)
76+
# Use here instead of None the function of the speech converter t2s()
77+
# add the function to translate text to speech (input parameters are destination_text, destination_lang)
78+
destination_speech = None
79+
pathstring = os.path.splitext(f)[0]
80+
pathstring_list = pathstring.split("/")
81+
audio_file = pathstring_list[len(pathstring_list) - 1] + f"_{destination_lang}_" + ".mp3"
82+
destination_speech.save(os.path.join(self.audio_path, audio_file))
83+
print(f"\n\nINFO : Converted the text file {f} into audio file successfully!\n\n")
84+
85+
for f in glob(f"{self.audio_path}/*.mp3"):
86+
try:
87+
print(f"\nPlaying {f}........\n")
88+
playsound.playsound(f)
89+
print(f".\n.\n.\n.\nFinished Playing the {f} file!")
90+
except KeyboardInterrupt:
91+
print("The preview of the mp3 file has been finished.")
92+
time.sleep(1)
93+
94+
95+
def main():
96+
audutorial = TutorialAudio()
97+
# Since the text file is written in english, the input language is english.
98+
input_lang = 'en'
99+
# English, French, German respectively in output_languages. We could add more number of languages according
100+
# to our choice and need in the below list.
101+
output_languages = ['en', 'fr', 'de']
102+
# Presently, the output audio stream has been set to German.
103+
audutorial.text_to_audio(input_lang, output_languages[2])
104+
105+
106+
if __name__ == '__main__':
107+
main()

0 commit comments

Comments
 (0)