2

so this is my main.py code-

import pyaudio
import speech_recognition as sr
import pyttsx3
from playsound import playsound
import kivy
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.screenmanager import ScreenManager,Screen
from kivy.properties import ObjectProperty
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.widget import Widget
from kivy.graphics import Rectangle
from kivy.graphics import Color
from kivy.uix.image import Image
from kivy.lang import Builder
kv = Builder.load_file('audibuddy.kv')

class MainWindow(Screen,FloatLayout):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.add_widget(Touch())
class speechtotext(Screen):
    pass
class texttospeech(Screen):
    pass
class WindowManager(ScreenManager):
    pass

class Touch(Widget):            
    def on_touch_down(self,touch):
        print("Mouse down",touch)
    def on_touch_move(self,touch):
        print("Mouse move",touch)
    def on_touch_up(self,touch):
        print("Mouse up",touch)

        

class Audibuddy(App):
    
    def build(self):
        return kv
if __name__  ==  "__main__":
    Audibuddy().run()

and this is my .kv file-

WindowManager:
    MainWindow:
    speechtotext:
    texttospeech:
<MainWindow>:
    GridLayout:
        Button:
            font_size: 40
            color: 1,1,1,1
    
    

    
    
    canvas:
        Color:
            rgba:0.16862745098,0.16862745098,0.16862745098,1
        Rectangle:
            pos:self.pos
            size :self.size
    BoxLayout:
        pos_hint:{'top':1.456}
        size_hint:2,0.57
            
        canvas:
            Color:
                rgba:0.09803921568,0.13725490196,0.17647058823,1
            Rectangle:
                pos:self.pos
                size:self.size
                    
           
    BoxLayout:
        pos_hint:{'left':1324,'top':1.44}
        Image:
            source:'image-removebg-preview(6).png'
            allow_strech:True
            keep_ratio:False
                 
    Button:
        id:settings_btn
        background_normal:"image-removebg-preview(10).png"
        background_down:"image-dark.png"
        allow_strech:True
        keep_ratio:False
        pos_hint:{"top":1,"right":0.99}
        size_hint: 0.09,0.09
                                            
    Label:
        text:"AudiBuddy"
        pos_hint:{"left":1, "top":1}
        font_size:40
    Button:
        id:speechtotext_btn
        text:"Speech to Text"
        pos_hint:{"x":0.15,"top":0.7}
        size_hint: 0.7,0.1
        background_colour:0.3,0.2,0,5,1
    Button:
        id:texttospeech_btn
        text:"Text to Speech"
        pos_hint:{"x":0.15,"top":0.55}
        size_hint: 0.7,0.1
    Button:
        id:exitapp_btn
        text:"Exit Application"
        pos_hint:{"x":0.15,"top":0.4}
        size_hint: 0.7,0.1
<speechtotext>:
<texttospeech>:

and it gives me this error:

File "C:\Users\admin_temp\Documents\GitHub\audibuddy\main.py", line 16, in <module>
     kv = Builder.load_file('audibuddy.kv')
   File "D:\Program Files\anaconda\lib\site-packages\kivy\lang\builder.py", line 306, in load_file
     return self.load_string(data, **kwargs)
   File "D:\Program Files\anaconda\lib\site-packages\kivy\lang\builder.py", line 404, in load_string
     widget = Factory.get(parser.root.name)(__no_builder=True)
   File "D:\Program Files\anaconda\lib\site-packages\kivy\factory.py", line 146, in __getattr__
     raise FactoryException('Unknown class <%s>' % name)
 kivy.factory.FactoryException: Unknown class <WindowManager>

I am not able to figure out what is wrong with my code.I am new to kivy and this is my first application. I am trying to put the main window ui that i desingned before inside the MainWindow class. Also,can anyone tell the answer fast as i have to submit the project tomorrow.

Edit:I edited the code a bit and now it looks like this main.py

import pyaudio
import speech_recognition as sr
import pyttsx3
from playsound import playsound
import kivy
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.screenmanager import ScreenManager,Screen
from kivy.properties import ObjectProperty
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.widget import Widget
from kivy.graphics import Rectangle
from kivy.graphics import Color
from kivy.uix.image import Image
from kivy.lang import Builder
kv = Builder.load_file('audibuddy.kv')

class Touch(Widget):            
    def on_touch_down(self,touch):
        print("Mouse down",touch)
    def on_touch_move(self,touch):
        print("Mouse move",touch)
    def on_touch_up(self,touch):
        print("Mouse up",touch)
class MainWindow(Screen):
    pass
class speechtotext(Screen):
    pass
class texttospeech(Screen):
    pass
class WindowManager(ScreenManager):
    pass



class Audibuddy(App):
    
    def build(self):
        return kv
if __name__  ==  "__main__":
    Audibuddy().run()

and the .kv file -

WindowManager:
    MainWindow:
    speechtotext:
    texttospeech:
<MainWindow>:
    Button:
            font_size: 40
            color: 1,1,1,1
    
    

    
    
    canvas:
        Color:
            rgba:0.16862745098,0.16862745098,0.16862745098,1
        Rectangle:
            pos:self.pos
            size :self.size
    BoxLayout:
        pos_hint:{'top':1.456}
        size_hint:2,0.57
            
        canvas:
            Color:
                rgba:0.09803921568,0.13725490196,0.17647058823,1
            Rectangle:
                pos:self.pos
                size:self.size
                    
           
    BoxLayout:
        Label:
            text:"audibuddy"
            pos_hint{"top":1,"left":1}
        
                 
    Button:
        id:settings_btn
        background_normal:"image-removebg-preview(10).png"
        background_down:"image-dark.png"
        allow_strech:True
        keep_ratio:False
        pos_hint:{"top":1,"right":0.99}
        size_hint: 0.09,0.09
                                            
    Label:
        text:"AudiBuddy"
        pos_hint:{"left":1, "top":1}
        size_hint:10,10
        font_size:40
    Button:
        id:speechtotext_btn
        text:"Speech to Text"
        pos_hint:{"x":0.15,"top":0.7}
        size_hint: 0.7,0.1
        background_colour:0.3,0.2,0,5,1
    Button:
        id:texttospeech_btn
        text:"Text to Speech"
        pos_hint:{"x":0.15,"top":0.55}
        size_hint: 0.7,0.1
    Button:
        id:exitapp_btn
        text:"Exit Application"
        pos_hint:{"x":0.15,"top":0.4}
        size_hint: 0.7,0.1
<speechtotext>:
<texttospeech>:

but now i get a different error -

File "C:\Users\admin_temp\Documents\GitHub\audibuddy\main.py", line 16, in <module>
     kv = Builder.load_file('audibuddy.kv')
   File "D:\Program Files\anaconda\lib\site-packages\kivy\lang\builder.py", line 306, in load_file
     return self.load_string(data, **kwargs)
   File "D:\Program Files\anaconda\lib\site-packages\kivy\lang\builder.py", line 373, in load_string
     parser = Parser(content=string, filename=fn)
   File "D:\Program Files\anaconda\lib\site-packages\kivy\lang\parser.py", line 402, in __init__
     self.parse(content)
   File "D:\Program Files\anaconda\lib\site-packages\kivy\lang\parser.py", line 511, in parse
     objects, remaining_lines = self.parse_level(0, lines)
   File "D:\Program Files\anaconda\lib\site-packages\kivy\lang\parser.py", line 614, in parse_level
     _objects, _lines = self.parse_level(
   File "D:\Program Files\anaconda\lib\site-packages\kivy\lang\parser.py", line 674, in parse_level
     if current_property[:3] == 'on_':
 TypeError: 'NoneType' object is not subscriptable
Krish
  • 31
  • 4

2 Answers2

1

friend dont do this

    class Audibuddy(App):

        def build(self):
            return kv

what u need to do is this just delete the build function from there

    class Audibuddy(App):

        pass 

and if that doesn't work then just make a kv file same name as your project and do the same thing , i hope this helps , and soory for poor explanation

VikLeo
  • 11
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 18 '21 at 12:04
-1

It is maybe because you are using anaconda If you are try using other alternatives

  • 2
    Hey thanks for your response, but I had already fixed it. I just renamed the .kv file from audibuddy.kv to main.kv and that somehow fixed it. – Krish Aug 18 '21 at 08:27