hello i make app with speechrecognize and kivy but when i use app i cant use microphone
i do so many things but it doesn’t work corctly
here is my code :
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock
from kivy import platform
import speech_recognition as sr
import threading
if platform == "android":
from android.permissions import request_permissions, Permission, check_permission # pylint: disable=import-error # type: ignore
request_permissions([Permission.INTERNET,Permission.RECORD_AUDIO])
class SpeechApp(App):
def build(self):
layout = BoxLayout(orientation='vertical')
self.label = Label(text="Listening")
self.button = Button(text="Start")
self.button.bind(on_press=self.start_listening)
layout.add_widget(self.label)
layout.add_widget(self.button)
threading.Thread(target=self.recognize_speech).start()
return layout
def recognize_speech(self):
recognizer = sr.Recognizer()
with sr.Microphone() as source:
while True:
self.label.text = "Listening"
audio = recognizer.listen(source)
try:
text = recognizer.recognize_google(audio, language='fa-IR')
if "کمک" in text:
self.update_label("recognize help")
else:
self.update_label(f"recognize: {text}")
except sr.UnknownValueError:
self.update_label("not recognize")
except sr.RequestError as e:
self.update_label(f"خطا در ارتباط با سرویس تشخیص گفتار: {e}")
def start_listening(self, instance):
threading.Thread(target=self.recognize_speech).start()
def update_label(self, text):
def update(dt):
self.label.text = text
Clock.schedule_once(update)
if __name__ == '__main__':
SpeechApp().run()
hello i make app with speechrecognize and kivy but when i use app i cant use microphone
thank you for your answers
and you for your help
New contributor
Arshan Pabarja is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.