-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
111 lines (89 loc) · 3.81 KB
/
main.py
File metadata and controls
111 lines (89 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# -*- coding: utf-8 -*-
# made by Ahmed ElSaeed
import sys, os
parent_folder_path = os.path.abspath(os.path.dirname(__file__))
sys.path.append(parent_folder_path)
sys.path.append(os.path.join(parent_folder_path, "lib"))
sys.path.append(os.path.join(parent_folder_path, "plugin"))
from flowlauncher import FlowLauncher
from gtts import gTTS
import os
from playsound import playsound
from pathlib import Path
import json
class AudFlow(FlowLauncher):
def query(self, query):
base_dir = Path(__file__).resolve().parent
Flow_launcher_main_dir = base_dir.parent.parent
flow_settings_dir = (Flow_launcher_main_dir / "Settings" / "Plugins" / "AudFlow" / "Settings.json")
if os.path.exists(flow_settings_dir):
with open(flow_settings_dir, "r") as f:
settings = json.load(f)
key = settings["execute_key"] if settings["execute_key"] else "|"
output = []
try:
if len(query.strip()) == 0:
output.append(
{
"Title": f":en text to speech {key}",
"SubTitle": f"use: 'au :ar expression {key}' to speak in arabic, after typing add '{key}' to run ",
"IcoPath": "Images/app.png",
}
)
else:
if len(query) > 3 and ":" in query[0]:
lang = query[1:3]
query = query[3:]
if query.endswith(key):
output.clear()
myobj = gTTS(text=query, lang=lang, slow=False)
myobj.save("AudFlow.mp3")
output.append(
{"Title": "Playing...", "IcoPath": "Images/play.png"}
)
playsound("AudFlow.mp3")
output.clear()
output.append({"Title": "End", "IcoPath": "Images/stop.png"})
else:
output.append(
{"Title": "Typing...", "IcoPath": "Images/type.png"}
)
else:
lang = "en"
if query.endswith(key):
output.clear()
myobj = gTTS(text=query, lang=lang, slow=False)
myobj.save("AudFlow.mp3")
output.append(
{"Title": "Playing...", "IcoPath": "Images/play.png"}
)
playsound("AudFlow.mp3")
output.clear()
output.append({"Title": "End", "IcoPath": "Images/stop.png"})
elif not query.endswith(key):
output.append(
{"Title": "Typing...", "IcoPath": "Images/type.png"}
)
except ValueError:
output.append(
{"Title": "Enter a valid language", "IcoPath": "Images/error.png"}
)
except IndexError:
output.append(
{
"Title": f":en text to speech {key}",
"SubTitle": f"use: 'au :ar expression {key}' to speak in arabic, after typing add '{key}' to run ",
"IcoPath": "Images/app.png",
}
)
except AssertionError:
output.append(
{"Title": "Enter a valid text", "IcoPath": "Images/error.png"}
)
except:
output.append(
{"Title": "Check your connection", "IcoPath": "Images/conn.png"}
)
return output
if __name__ == "__main__":
AudFlow()