-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathutils.py
45 lines (33 loc) · 1.01 KB
/
utils.py
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
import random
import socket
import subprocess
import threading
import traceback
from logging import getLogger
from sys import platform
import pyttsx3
logger = getLogger('Utils')
logger.setLevel('DEBUG')
def rand_int(min_value=0, max_value=100):
return random.randint(min_value, max_value)
def say(text):
if platform == "darwin":
subprocess.Popen(['say', '-r', '10000', text])
elif platform == "win32":
def wrapper():
tts = pyttsx3.init()
tts.say(text)
tts.runAndWait()
threading.Thread(target=wrapper).start()
else:
logger.warning(f'{platform} 暂不支持TTS语音播报')
def get_interface_ip() -> str:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
return s.getsockname()[0] or '获取失败'
except Exception:
traceback.print_exc()
return '获取失败'
def add_cancel_button(buttons: list):
return buttons + [{'label': '放弃', 'type': 'cancel'}]