我试图用Kivy 2.0.0和python 3.6创建文本到语音 我已经安装了pyttsx3。 我已经创建了一个文本框和按钮以及一个从文本框说话的函数
它在计算机中确实会说话,也能很好地工作。 然后我转换成apk并安装了它。 当我按“说话”按钮时,它崩溃了
我的python主文件
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.widget import Widget
import pyttsx3
Builder.load_file('tts.kv')
class MyLayout(Widget):
def speak(self):
word=self.ids.word_input.text
engine=pyttsx3.init()
volume = engine.getProperty('volume')
engine.setProperty('volume',1.0)
engine.say(word)
engine.runAndWait()
class myApp(App):
def build(self):
return MyLayout()
if __name__=="__main__":
myApp().run()
My kivy file
<MyLayout>:
FloatLayout:
size:root.width,root.height
TextInput:
id:word_input
multiline: False
size_hint:(.6,.1)
pos_hint:{'center_x':.5,'top':.8}
Button:
text:"Speak"
size_hint:(.6, .2)
font_size:35
pos_hint:{'center_x':.5,'top':.6}
on_press:root.speak()
如何让android对插入的文本说话?我们需要在Buildozer文件中更改什么
提前谢谢
如果我是正确的,那么
pyttsx3
库只支持桌面应用程序,这就是为什么我建议尝试plyer library,它旨在直接支持android/ios。它也是由Kivy
库后面的团队开发的旁注:如果你打算在Windows上也使用这个应用程序,我建议你要么坚持使用
pyttsx3
库,要么如果你想使用plyer
,那么你必须在你的运行目录或espeak.exe
中有PATH
应用程序,你只需在谷歌上搜索即可找到它相关问题 更多 >
编程相关推荐