将LIVE SPEECH与Tkinter GUI接口

时间:2019-06-29 19:26:20

标签: python tkinter speech-recognition pocketsphinx

我想将Pocketsphinx livepeech与Python tkinter GUI进行接口连接,以使GUI在前端可见,而Livespeech在后端工作。但是,当我将tkinter代码与livepeech代码合并时, livepeech代码始终首先运行,直到我停止代码,GUI才会显示;因此,我将无法执行所需的任务。.,

    #*********************************** IMPORTING MODULES*****************
import tkinter
from tkinter import*
import tkinter.messagebox
import sqlite3
import os
from pocketsphinx import LiveSpeech, get_model_path


conn = sqlite3.connect('portal.db')
c = conn.cursor()

window = tkinter.Tk()
window.title("Smart Notice Board")

top = Canvas(window,width=400,height=200)
top.pack(fill=X)

def portal():
    print("2")

button_5 = Button(text='PORTAL SYSTEM', height = 2, width=17, activebackground = '#33B5e5', bg = 'brown', fg = 'white',command  = portal )
top.create_window(80,80, anchor='nw', window = button_5) 

#****************  TEXT TO SPEECH CODE***************

model_path = get_model_path()

speech = LiveSpeech(
    verbose=False,
    sampling_rate=16000,
    buffer_size=2048,
    no_search=False,
    full_utt=False,
    hmm=os.path.join(model_path, 'en-us'),
    lm=os.path.join(model_path, '8582.lm'),
    dic=os.path.join(model_path, '8582.dict')
)

for phrase in speech:
    print(phrase)
    a=str(phrase)
    if a == "HOME":
        print('ok')
        portal()
        print('1')

结果附在下面; 只有现场演讲才能运行

代码退出时GUI打开

After adding Multiprocessing

0 个答案:

没有答案