sudo apt-get install espeak #先安装这个库
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyttsx3==2.90 #再安装pyttsx3 pyinstaller
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyinstaller==6.3.0 # 安装打包的库
#!/usr/bin/env python
#-*-coding:utf-8-*-
import socket
import pyttsx3
def extract_ip():
st = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
#st.connect(('10.255.255.255', 1))
st.connect(('8.8.8.8', 80))
IP = st.getsockname()[0]
except Exception:
IP = '127.0.0.1'
finally:
st.close()
return IP
ip = extract_ip()
print(ip)
engine = pyttsx3.init()
engine.setProperty('rate', 150) # 设置语速
engine.setProperty('voice', 'zh') # 设置语言
ip = ip.replace('.', '点')
engine.say(ip)
engine.say(ip)
engine.runAndWait()
切换到当前目录
pyinstaller -F -w xx_ip.py #xx_ip.py为你的文件名
在当前目录会生成dist文件夹,里面同名文件即为可执行文件。
浏览选择可执行文件: