Mycroft Community Forum

Text input instead of voice

In my skill I need the user to enter a word letter by letter.
Is there a way the user can enter the input with the keyboard instead of voice recordings?

Thank You,
Alon Yom Tov

Would something like this be useful?

I am busy with a Python3 program for a graphical interface with themes for Mycroft.
I stripped out some code for you which you can easily use in your own skill or scripts.

I uses your default voice as output.
you can use it as a definition in your skill

def speak():

        tools=Tk()
        tools.resizable(False, False)
        def retrieve_input():
            inputValue=toolsinput.get("1.0", "end-1c")
           # print(inputValue)
            if inputValue == "":
               subprocess.run("mycroft-speak", text=True, input="Sorry no text detected")
            else:
                subprocess.run("mycroft-speak", text=True, input=inputValue)
           #print(subprocess.run("mycroft-speak", text=True, input=inputValue))

        tools.title(' Mycroft Speak Test')
        toolstext = Label(tools, text=" Mycroft Open Source Voice Assistant Speak test")
        toolstext2 = Label(tools, wraplength='250', text="With this tool you can test the Mycroft Speak Engine. Type the words you want the Mycroft Speak Engine to speak and press the \u263a button.\n\nNote: uses your default speech voice ")
        toolsinput = Text(tools, height=10, width=50)
        toolsspace = Label(text = " ")


        toolsbutton = Button(tools, font=('Arial', 24, 'bold'), text=" \u263a ",  command=lambda: retrieve_input())
        toolsspace.pack()

        toolsbutton.config(bg='blue', fg='white', bd=2)
        toolstext.config(font=('Arial', 10, 'bold'))
        toolstext.pack(padx=15, pady=15)
        toolstext2.pack(padx=15, pady=15)
        toolsinput.pack(side=LEFT, padx=30, pady=10)
        toolsbutton.pack(side=RIGHT, padx=40, pady=10)

        toolsspace.pack()

The whole code with interface ( i stripped out all theme things you do not need). Copy / paste save as speak.py, then python speak.py


#!/usr/bin/env python3
#simple splash screen

try:
# for Python2
from Tkinter import *
except ImportError:
# for Python3

from tkinter import *
from tkinter import Tk, Frame, messagebox, Menu
from time import time, sleep, clock, perf_counter

make sure windows appear in center of screen

root = Tk()
#root.geometry("+%

Gets the requested values of the height and widht.

windowWidth = root.winfo_reqwidth()
windowHeight = root.winfo_reqheight()
print(“Width”, windowWidth, “Height”, windowHeight)

Gets both half the screen width/height and window width/height

positionRight = int(root.winfo_screenwidth()/3 - windowWidth/3)
positionDown = int(root.winfo_screenheight()/3 - windowHeight/3)

Positions the window in the center of the page.

Set Title and make sure the window is not resizable

root.geometry("+{}+{}".format(positionRight, positionDown))
root.title(’ Mycroft Interface Linux’)
root.configure( width=700)
root.resizable(False, False)

button frame

it was a pain in the @ss to justify all buttons

if there is an easier please edit

but_frame = Frame(root, relief=SUNKEN, pady=1)
but_frame2 = Frame(root, pady=1)
but_frame3 = Frame(root, pady=10)
but_frame33 = Frame(root, pady=15)
but_frame4 = Frame(root, bg=’#616161’, pady=5)
but_frame4.config(bd=2)

def start():
import subprocess
subprocess.call(“mycroft-start all”, shell=True)
messagebox.showinfo(“Info”, “Mycroft Services started. \nPlease restart M.I.L.”)
root.destroy()
def stop():

import subprocess
subprocess.call("mycroft-stop all", shell=True)
messagebox.showinfo("Info", "Mycroft Services stopped. \nPlease restart M.I.L.")
root.destroy()

define labels and buttons

dis = Label(but_frame)
title = Label(but_frame, wraplength=550, compound=‘center’, font=(‘Arial’, 14, ‘bold’), text=“Mycroft Open Source Voice Assistant Interface for Linux”)
lbl = Label(but_frame, wraplength=550, text=“Note: This program is nothing special. It is a Python script which calls some Bash scripts. I wrote it fast and ugly. There is lots of room for improvements. I encourage everybody to edit and enhance it. Also: It might be strange scaled on some devices.”)
choose=Label(but_frame, wraplength=500, text=“Choose a Theme\n( NOTE: use voice command: ‘‘exit interface’’ to go back to this menu.)\n”)

make a nice layout

title.pack(side=TOP, padx=10,pady=10 )
lbl.pack(side=TOP, padx=10,pady=10)
choose.pack(side=TOP, padx=10, pady=15)

showing a button frame

but_frame.pack(side=TOP)

but_frame2.pack()

import subprocess
found = subprocess.run("/bin/ps -x|grep mycroft.messagebus.service|grep -v ‘grep’|wc -l", stdout=subprocess.PIPE, shell=TRUE)

if found.stdout == b’0\n’:
found.stdout = " Note: Mycroft background service not running"
found.stdout = u’\u2718’ + " " + found.stdout
found.bg = ‘red’
found.stdout = found.stdout
butstart = Button(but_frame4, text=" Start Mycroft Services", command=start)
else:

found.stdout = "Mycroft background service is running"
found.stdout = u'\u2611' + " " + found.stdout
found.bg = 'green'
found.stdout = found.stdout
butstart = Button(but_frame4, text=" Stop Mycroft Services", command=stop)

frame 3/33/4

line = Label(but_frame33, font=(‘Arial’, 10), text=" ")
text5 = Label(but_frame4, font=(‘Arial’, 10), bg=found.bg, fg=‘white’, text=found.stdout)
text5.config(anchor=CENTER)
line.pack()
text5.pack(side=LEFT, padx=100, pady=0)
butstart.pack(side=RIGHT, padx=100)
but_frame3.pack(side=BOTTOM)
but_frame33.pack(side=TOP)
but_frame4.pack(side=BOTTOM)
photologo = PhotoImage(file=“mil-logo.png”)

mainloop menu

def about():

        aboutwin=Tk()

        def openwgit():
            website = messagebox.askquestion('Open website?', 'Open website: https://github.com/bastiaanwilliams?',
                                             icon='warning')

            if website == 'yes':

                import subprocess
                subprocess.call("/usr/bin/xdg-open https://github.com/bastiaanwilliams", shell=True)
            else:
                aboutwin.destroy()
        aboutwin.resizable(False, False)
        aboutwin.title(' About ')
        millogo = Label(aboutwin)
        import platform
        info = "System: " + platform.platform()
        millogo.config(text="M.I.L", font=('Arial', 26, 'bold'), activebackground=None, bd=1)
        abouttext = Label(aboutwin, text=" Mycroft Open Source Voice Assistant Interface for Linux")
        abouttext2 = Label(aboutwin, text="Author: Bastiaan Williams, bastiaanwilliams@protonmail.com")
        abouttext3 = Label(aboutwin, text=" Version: 0.1\n")
        aboutsystem = Label(aboutwin, text=info)
        abouttextw = Button(aboutwin, font=('Arial', 10, 'underline'), text="https://github.com/bastiaanwilliams")
        millogo.pack(padx=0, pady=0)
        abouttext.pack()
        abouttext2.pack()
        abouttext3.pack()
        aboutsystem.pack()
        abouttextw.config(anchor=CENTER, bg=None, bd=0, fg='blue', activebackground=None, command=openwgit)
        abouttextw.pack(padx=0, pady=6)

def systeminfo():
import platform, socket, re, uuid, os
from requests import get
import urllib.request

        systeminfo=Tk()
        systeminfo.resizable(False, False)
        systeminfo.title(" System Information ")

        ip = urllib.request.urlopen('https://ident.me').read().decode('utf8')
        info1 = platform.system()
        info2 = platform.release()
        info3 = platform.version()
        info4 = socket.gethostname()

    #geting internal IP
        inforight = info1 + "\n" + info2 + "\n" + info3 + "\n" + info4 + "\n" + ip
        infoleft = "System:" + "\n" + "Release:" + "\n" + "Version:" + "\n" + "Hostname:" + "\n" + "Public IP Address:"
        infowindow = Label(systeminfo, text=infoleft)
        infowindow2 = Label(systeminfo, text=inforight)
        infowindow2.config(font=('Arial', 10, 'bold'))
        infowindow.pack(side=LEFT, padx=10, pady=10)
        infowindow2.pack(side=RIGHT, padx=10, pady=10)

def speak():

        tools=Tk()
        tools.resizable(False, False)
        def retrieve_input():
            inputValue=toolsinput.get("1.0", "end-1c")
           # print(inputValue)
            if inputValue == "":
               subprocess.run("mycroft-speak", text=True, input="Sorry no text detected")
            else:
                subprocess.run("mycroft-speak", text=True, input=inputValue)
           #print(subprocess.run("mycroft-speak", text=True, input=inputValue))

        tools.title(' Mycroft Speak Test')
        toolstext = Label(tools, text=" Mycroft Open Source Voice Assistant Speak test")
        toolstext2 = Label(tools, wraplength='250', text="With this tool you can test the Mycroft Speak Engine. Type the words you want the Mycroft Speak Engine to speak and press the \u263a button.\n\nNote: uses your default speech voice ")
        toolsinput = Text(tools, height=10, width=50)
        toolsspace = Label(text = " ")


        toolsbutton = Button(tools, font=('Arial', 24, 'bold'), text=" \u263a ",  command=lambda: retrieve_input())
        toolsspace.pack()

        toolsbutton.config(bg='blue', fg='white', bd=2)
        toolstext.config(font=('Arial', 10, 'bold'))
        toolstext.pack(padx=15, pady=15)
        toolstext2.pack(padx=15, pady=15)
        toolsinput.pack(side=LEFT, padx=30, pady=10)
        toolsbutton.pack(side=RIGHT, padx=40, pady=10)

        toolsspace.pack()

menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label=“Exit”, command=root.quit)
menubar.add_cascade(label=“File”, menu=filemenu)

toolsmenu = Menu(menubar, tearoff=0)
toolsmenu.add_command(label=“System Information”, command=systeminfo)
toolsmenu.add_command(label=“Test Mycroft Speak Engine”, command=speak)
menubar.add_cascade(label=“Tools”, menu=toolsmenu)

helpmenu = Menu(menubar, tearoff=0)

helpmenu.add_command(label=“About…”, command=about)
menubar.add_cascade(label=“Help”, menu=helpmenu)

root.config(menu=menubar)
root.mainloop()

----------------------------------------------------------------------------------------------------------------- END

Sorry for the mess :slight_smile:
You can still select all and copy / paste in file