如何从另一个模块获取列表并在Python中与语音配合使用

问题描述 投票:-1回答:1

我正在尝试使用python构建语音助手。但是我有一些问题。

我有一个包含单词的assistantInputs.py文件,以及作为主程序的main.py。

这是我在assistantInputs.py中的代码:

hello = ["hi","hey","hello","greetings"]

这是我在main.py中的代码:

import assistantInputs

if voice_data in hello:
    print("Hey!")

'voice_data'允许我说出并识别我的声音。

但是它不起作用。我应该怎么办?

python voice-recognition voice voice-recording assistant
1个回答
0
投票

当使用import assistantInputs导入模块时,模块内部的变量可以assistantInputs.hello的形式访问,而不仅仅是hello。您也可以尝试不太喜欢的方法

from assistantInputs import *

访问不带任何前缀的hello变量。

© www.soinside.com 2019 - 2024. All rights reserved.