调整语音音量大小
bash
pactl list sinks
pactl set-sink-volume 15 12345
# 15可以改成别的id
安装pip install pyttsx3
bash
sudo apt-get update
sudo apt-get install espeak
sudo ldconfig
pip3 install pyttsx3
代码
python
import pyttsx3
import threading
def speak_work(text):
engine = pyttsx3.init()
engine.setProperty('volume', 1.0) # 设置音量(0.0到1.0)
engine.setProperty('rate', 200) # 设置语速(默认为200)
engine.setProperty('voice', 'zh')
engine.say(text)
engine.runAndWait()
def speak(text):
speak_thread = threading.Thread(target=speak_work, kwargs={'text': text})
speak_thread.start()
if __name__ == '__main__':
speak('死舔狗,去他妈的,舔的人家女生快保研')