1

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

After adding Multiprocessing

  • Time to learn about https://docs.python.org/2/library/multiprocessing.html – Nikolay Shmyrev Jun 29 '19 at 20:01
  • i have acted upon your advice;divide both codes in function and includes\ multiprocessing in the code but only difference in the result is that NOW it only opens livespeech (fun2 in code) and doesnot open tkinter GUI(fun) whereas previously it open GUI when code stops but now it won't do that – Hassaan Khan Jun 30 '19 at 18:18
  • GUI should be the main thread. – Nikolay Shmyrev Jun 30 '19 at 18:36
  • Tried GUI as main thread too and call livespeech after that, still GUI opens when i exit the code – Hassaan Khan Jun 30 '19 at 20:02
  • You can check https://stackoverflow.com/questions/47670677/python-tkinter-multiprocessing-progress for the proper implementation with pipes between thread and main loop. – Nikolay Shmyrev Jul 02 '19 at 09:38
  • Possible duplicate of [Python Tkinter multiprocessing progress](https://stackoverflow.com/questions/47670677/python-tkinter-multiprocessing-progress) – Nikolay Shmyrev Jul 02 '19 at 09:38

0 Answers0