首页 > 解决方案 > 即使在调试之后,Kivymd 应用程序也会在启动时崩溃

问题描述

我一直在编写一个代码来制作一个可以将麦克风输入流式传输到扬声器输出的应用程序,它可以在 PyCharm 或任何 IDE 上完美运行,但是一旦成功安装并且你首先启动它就会崩溃,IDK 为什么到目前为止还没有解决方案工作这是我的第一个 python 应用程序。谁能帮忙

我使用 google colab 运行 builddozer,但它不工作。谁能告诉我这里有什么问题?

import argparse
import kivy
from kivymd.app import MDApp
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
import sounddevice as sd
import numpy  # Make sure NumPy is loaded before it is used in the callback
assert numpy  # avoid "imported but unused" message (W0611)

def int_or_str(text):
    """Helper function for argument parsing."""
    try:
        return int(text)
    except ValueError:
        return text


parser = argparse.ArgumentParser(add_help=False)
parser.add_argument(
    '-l', '--list-devices', action='store_true',
    help='show list of audio devices and exit')
args, remaining = parser.parse_known_args()
if args.list_devices:
    print(sd.query_devices())
    parser.exit(0)
parser = argparse.ArgumentParser(
    description=__doc__,
    formatter_class=argparse.RawDescriptionHelpFormatter,
    parents=[parser])
parser.add_argument(
    '-i', '--input-device', type=int_or_str,
    help='input device (numeric ID or substring)')
parser.add_argument(
    '-o', '--output-device', type=int_or_str,
    help='output device (numeric ID or substring)')
parser.add_argument(
    '-c', '--channels', type=int, default=2,
    help='number of channels')
parser.add_argument('--dtype', help='audio data type')
parser.add_argument('--samplerate', type=float, help='sampling rate')
parser.add_argument('--blocksize', type=int, help='block size')
parser.add_argument('--latency', type=float, help='latency in seconds')
args = parser.parse_args(remaining)



class THAGrid(GridLayout):
    def __init__(self,**kwargs):
        super(THAGrid, self).__init__()
        self.cols = 2
        self.add_widget(Label(text="Press To Start"))

        self.press = Button(text = "Press to Hear")
        self.press.bind(on_press=self.hear)
        self.add_widget(self.press)

    def hear(self, instance, ):

        def callback(indata, outdata, frames, time, status):
            if status:
                print(status)
            outdata[:] = indata


        try:
            with sd.Stream(device=(args.input_device, args.output_device),
                       samplerate=args.samplerate, blocksize=args.blocksize,
                       dtype=args.dtype, latency=args.latency,
                       channels=args.channels, callback=callback):
                print('#' * 80)
                print('press Return to quit')
                print('#' * 80)
                input()

        except KeyboardInterrupt:
            parser.exit('')
        except Exception as e:
            parser.exit(type(e).__name__ + ': ' + str(e))

class TheHealingTech(MDApp):
    def build(self):
        return THAGrid()


if __name__ == "__main__":
    TheHealingTech().run()

标签: pythonandroidkivymd

解决方案


尝试使用kivy 2.0.0kivymd==0.104.2。将它们安装在 pycharm 的插件槽设置中。你buildozer.spec应该是这样的:

requirements = python3,kivy==2.0.0,kivymd==0.104.2,pillow,sdl2_ttf==2.0.15,argparse,numpy

推荐阅读