问题
I want to interface pocketsphinx livespeech with Python tkinter GUI in such a way that GUI is visible on frontend and Livespeech works on Back-end.But when i merge tkinter code with livespeech code; livespeech code always runs first and GUI not shows till i stop the code;so i won't be able to perform my required task..,
#*********************************** 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')
results are attached below; Only live speech runs
GUI opens when code exit
来源:https://stackoverflow.com/questions/56820304/interfacing-live-speech-with-tkinter-gui