File size: 2,722 Bytes
66ca64a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import random
import string
import requests

# Deleting audio
def deleteAudio(path: str, waitInSeconds: int = 0):
    os.system("rm /home/ubuntu/api/static/{}".format(path))

# Signatures!!! Wow!!!
def checkSignature(signature: str):
    signatureList = [
        "008610493EAF05823A1C409C551511BA22C9139B97E78C7AC32E36A5992D5FFB2F846B312EE24ED8FA0AEE83700498F341A1AA46E148F05725867D7C51459A1F",
        "B2A61FBD11D39A611951D803045B7FCE8A76360099127BA9DD1F6B0B691CFF3320D11916AB5297B811149C3BC65D97777D1DE588249863A7C0E877AD13235C99"
    ]
    return signature in signatureList

# Hook for yt-dlp
def thisIsHook(d):
    if d['total_bytes'] > 52428800:
        print("\nFILE IS BIG, ABORT!!!\n")
        raise Exception(f"Too long file (recieved {d['total_bytes']/1048576}MB, max is 50MB)")
        
# Recognizing things
def req(access_token, meth, path, params, **kwargs):
    full_url = "https://api.wit.ai" + path
    headers = {
        "authorization": "Bearer " + access_token,
        "accept": "application/vnd.wit." + "20221114" + "+json", 
    }
    headers.update(kwargs.pop("headers", {}))
    rsp = requests.request(meth, full_url, headers=headers, params=params, **kwargs)
    if rsp.status_code > 200:
        raise Exception(
            str(rsp.status_code)
            + " ("
            + rsp.reason
            + ")"
        )
    try: r = rsp.json()
    except: r = rsp.text
    if "error" in r:
        raise Exception(json["error"])

    return r
def dictation(access_token, audio_file, headers=None, verbose=None):
    params = {}
    headers = headers or {}
    if verbose:
        params["verbose"] = True
    resp = req(
        access_token,
        "POST",
        "/dictation",
        params,
        data=audio_file,
        headers=headers,
    )
    return resp
def clean(text):
    if text not in ['', None]:
        return text.replace('?', '').replace('!', '').replace(';', '').replace('.', '').replace(',', '')
def delivering(text):
    result = []
    temp = None
    toPush = None
    tempLength = 0
    for dirtLine in text.split('\n'):
        if '"text"' in dirtLine:
            line = dirtLine[11:-1]
            if temp == None: temp = line
            else:
                if temp in line: toPush = line
                else:
                    temp = line
                    result.append(toPush)
    return ' '.join(result)
def devRaw(text):
    result = []
    for line in text.split('\n'): #line[11:-1]
        if '"text"' in line:
            result.append(line[11:-1])
    return result
    
def randString(len: int = 16):
    return ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(len))