65523
VoiceTextのGUI操作をkivyで作っているのですが、nameerrorが出てしまって動きません。どうやったらいいか教えて下さい。  
main.py

```

    # -*- coding: utf-8 -*
    from pyVoiceText import VoiceText
    from kivy.app import App
    from kivy.uix.boxlayout import BoxLayout
    from kivy.uix.spinner import Spinner
    from kivy.core.window import Window
    from kivy.core.text import LabelBase, DEFAULT_FONT
    from kivy.resources import resource_add_path
    from kivy.uix.textinput import TextInput
    from kivy.properties import StringProperty
    
    resource_add_path('/System/Library/Fonts/')
    LabelBase.register(DEFAULT_FONT, 'ヒラギノ明朝 ProN.ttc')
    #Window.size = (500, 350)
    
    class CustomSpinner(Spinner):
        pass
    
    class MainRoot(BoxLayout):
        talk = 'テキスト'
        text = StringProperty('')
    
        def on_speaker(self, speaker):
            speaker = "'"+speaker+"'"
            print(speaker)
            return speaker
    
        def on_format(self, format):
            format = "'out"+format+"'"
            print(format)
            return format
    
        def on_command(self):
            self.text = self.ids.textInput.text
            text = self.text
            api_key = 'xxxxx'
    
            voice_text = VoiceText(api_key)
            mp3 = voice_text.fetch(text, speaker, format)
    
    class MainApp(App):
        def build(self):
            self.title = 'VoiceText'
    
    if __name__ == "__main__":
        MainApp().run()
    
    
```

main.kv

```

    MainRoot:
    
    <MainRoot>:
        BoxLayout:
            orientation: "vertical"
    
            CustomSpinner:
                text: '話者を選択して下さい'
                values: 'show', 'haruka', 'hikari', 'takeru', 'santa', 'bear'
                size_hint: None, None
                size: root.width, root.height/4
                pos_hint: {"x":0, "top":1}
                on_text: root.on_speaker(self.text)
    
            CustomSpinner:
                text: 'フォーマット形式を選択して下さい'
                values: '.wav', '.ogg', '.mp3'
                size_hint: None, None
                size: root.width, root.height/4
                pos_hint: {"x":0, "top":1}
                on_text: root.on_format(self.text)
    
            Label:
                size: root.width, root.height/4
                text: root.talk
    
            TextInput:
                id: textInput
                size: root.width, root.height/4
                multiline: False
                text: ''
                hint_text: 'しゃべらせたい言葉を入力して下さい'
    
            Button:
                size: root.width, root.height/4
                text: '実行'
                on_press: root.on_command()
    
    
```
CC BY-SA 4.0
2020-04-09T12:38:43.163
65498
2020-04-10T12:38:32.813
question
python
他の関数から関数の中の変数を取り出す
Kivyはまったく知らないのですが、もし、`on_speaker`と`on_format`に渡されたものを後で`on_command`の中で使いたいという質問なのであれば、`MainRoot`オブジェクトの`self`に保存してはだめでしょうか？

```

        def on_speaker(self, speaker):
            self.selected_speaker = ...
    
        def on_format(self, format):
            self.selected_format = ...
    
        def on_command(self):
            ...
            mp3 = voice_text.fetch(text, self.selected_speaker, self.selected_format)
    
```
CC BY-SA 4.0
2020-04-10T12:38:32.813
65523
2020-04-10T12:38:32.813
36010
65498
answer