Hooking into the Mycroft output from the command line

FYI, I couldnt get the plasmoid required for install of the Desktop Control skill installed on Kubuntu 18.10, and created a GitHub issue here: https://github.com/MycroftAI/mycroft-core/issues/2600. I’m working to find a direct method of hooking into the Mycroft output to the command line. Anyone with suggestions, please post, thanks!

Working on a solution, so far this works to capture output, extract the command from the voice.log:
tail -f -n 1 /var/log/mycroft/voice.log | grep --line-buffered -Po "(?<=').*?(?=')" | xargs -t -n1 -d '\n' echo
This will actually execute the spoken command:
tail -f -n 1 /var/log/mycroft/voice.log | grep --line-buffered -Po "(?<=').*?(?=')" | xargs -t -n1 -d'\n' -I {} sh -c "{}"
Need to make a CLI Command skill that recognizes a keyword like ‘command’ or ‘bash’ to retrieve the last phrase and excute. Also want a loop back two times before giving up after the recording timeout.

Will continue development notes in the GitHub issue…

1 Like

I’d use python and the message bus, then you can just pull the text and run it directly instead of the bash fun.

Thanks @baconator, could you add a quick example to save me some time searching the docs? …havent used the bus system yet…

Actually, I was just about to tackle ‘python -m mycroft.messagebus.send “mycroft.mic.listen”’ from the microft-listen function, but I wasnt sure if I needed to be in the venv or not.

Also, I have a couple quick questions maybe you could rescue me from more trial and error… I just tried adding ‘barge-in’ functionality following the link (Mycroft not responding during audio output?), but when I paste in the snippet below to mycroft.conf, it complains. Ive gone over the syntax several time with no luck. Ill post the error in a second, but maybe it is inconsistent indentation like in Python or EOF?

“listener”: {
“mute_during_output”: false

@baconator and @gez-mycroft How strange, when copy and pasting from the forum, link above, the double quotes are not acceptable to the mycroft-config edit user checking. See the difference below. I pasted in a different snippet I saw about disabling online Mycroft Home in the README, because I read the warning about port 8181 and am concerned about security, and have not found detailed answers on how to secure the system. I tried UFW and the iptables commands from links I will post below.

 "skills": {
    "blacklisted_skills": [

But for the double quotes, notice the difference, actually it will probably render both with unaccepted quote font…(but it actually shows them differently) it looks like they are ‘backward’ double quotes:

“listener”: {
“mute_during_output”: false

Doesnt work:
“listener”: {
“mute_during_output”: false

That is from this post:

For Python mbus commands, install package using: mycroft-pip install mycroft-messagebus-client, after activating the venv with source venv-activate.sh` in ~/mycroft-core/venv-activate.sh. From: https://mycroft-ai.gitbook.io/docs/mycroft-technologies/mycroft-core/message-bus

Then python3 -m mycroft.messagebus.send 'speak' '{ "utterance": "test"}'

From: https://mycroft-ai.gitbook.io/docs/mycroft-technologies/mycroft-core/message-types

python3 -m mycroft.messagebus.send 'mycroft.mic.listen' will trigger as a Wakeword.

python3 -m mycroft.messagebus.send 'recognizer_loop:utterance' '{ "utterances": "what is the weather"}' will trigger as an Utterance, but doesnt seem to work. I did remove some of the parameters, but there is no fail or error message. It does not show up in the mycroft-cli-client like the above to commands similarly truncated.

@baconator, @gez-mycroft and @andlo I dont see how to intercept the Utterance…?

I see this using python but it doenst use the messagebus as suggested: Catch and print what User Said
message.data.get('utterances')[0]) …or does it?

Is there a command line equivalent?

git clone https://github.com/MycroftAI/skill-speak /opt/mycroft/skills/skill-speak

Just created a skill following (https://mycroft-ai.gitbook.io/docs/skill-development/introduction/your-first-skill) using mycroft-msk create and went to dir ll /opt/mycroft/skills/cli-command-skill/ but there is no ‘dialog’ dir as in the docs…?
There is a dialog file in /opt/mycroft/skills/cli-command-skill/locale/en-us/command.cli.dialog. Definitely some deviation from the Docs for QuickStart.

Also, is this stored in Mycrft repo or in my own? … my own. Interesting…

Console out in Python? https://mycroft-ai.gitbook.io/docs/mycroft-technologies/mycroft-core/message-types#mycroft-debug-log Nope.


self.log.info("This is an info level log message.")

Bummer, basic skill template not functioning. Even after trying to use activate cli-command-skill in the mycroft-cli-client, and having it show up in the skills list. Even after restart all.

ERROR | 1263 | mycroft.skills.skill_loader:_communicate_load_status:287 | Skill cli-command-skill failed to load
'inconsistent use of tabs and spaces in indentation`

If I have to restart all services and reload the cli-client, development cycle will be very slow.

After restarting all several times and loading the cli-client, I now receive this error and the initialization messages are different in the cli-client and the custom skill doesnt load. Restart all again doesnt help, nor does mycroft-stop all. At a loss here on how to proceed, no stranded processes left to be found. Seems like some kind of device issue, maybe internet, but I have that disabled and am working locally. I did get the custom command to load once, and was working on an import error and then a @intent_handler versus #@intent_file_handler between the template skill and the ‘parrot skill’ I snipped some code from for the Utterance read.

2020-05-31 21:47:16.067 | WARNING  | 10696 | mycroft.api:check_remote_pairing:531 | Could not get device info: PermissionError(13, 'Permission denied')
2020-05-31 21:47:16.522 | INFO     | 10696 | mycroft.messagebus.load_config:load_message_bus_config:33 | Loading message bus configs

Skills are automatically reloaded on changes in the __init__.py so you will not need to restart mycroft after each change. If you want to force a reload while developing you can run touch /opt/mycroft/skills/MY_SKILL/__init__.py (quicker and easier than :deactivate + :activate in the CLI)

Sounds a bit like your editor might have malformed the example skill? replacing some space indentation with tabs or vice-versa (in python indentation has meaning and will cause trouble if not consistent)

The example you link is using the “messagebus client” A small module that can be used from third-party applications interacting with mycroft so the syntax is a bit simplified.

python3 -m mycroft.messagebus.send 'recognizer_loop:utterance' '{ "utterances": "what is the weather"}'

May be a typo…should probably be

python3 -m mycroft.messagebus.send 'recognizer_loop:utterance' '{ "utterances": ["what is the weather"]}'

(will verify this after coffee)

Edit: verified, should be a list of utterances as above

/ Å

Thanks very much for they reply. Indeed I did take out the brackets, and didnt realize that was in list/array format as the example in the docs only has one member (‘text’ I believe), which means I can include multiple utterances?.. great! And yes it does work now, thanks.

Good to know about the Touch ini.py. Will try… although I would have thought that saving in the editor would have done the same, will retest… yes, this is working, saving in editor does create changes reflected in cli-client.

Still getting the device permission error… tracking down clues… Its only upon running the cli-client. Restarting would probably fix it, but I have a browser window open with unfinished work in it. Would be better to restart whatever is hanging… Also the error is likely related to the fact I have Remote Home disabled in my config (mentioned above). So the only problem is not getting the skills errors in the cli-client really.

So, I just tried sending an Utterance (with correct format) for my custom skill and its not recognizing it. Going to use the logs hopefully to debug without the cli-client… I dont see a log that shows the main loading (and errors) for the skills.

Looking forward, does it matter which intent handler method I import and use (@intent_handler versus #@intent_file_handler)? I realize there must be differences implied in the names, but both are used in simple skills with similar functionalities and used without the other one (function independently) which leads me to believe they are interchangeable to get a basic skill to start working.

EDIT: Aha! I found I had hastily exited out of the mycroft-config edit user Vim window and it was stuck running in the background… knew it was time to go to bed!.. yay, onward!

Well, the cli-client is loading (logging) normally, but my custom skill still isnt being loaded. I would really like to be able to search this logging, but I dont see it anywhere in the log files in the docs which are in /var/log/mycroft/ or even in /var/log/syslog.

Seem to have found the issue with cli-client, is related to the symlinking of /mycroft-core to two different installs, one in Home dir one on a partition with more spaces and symlinked… thats good, just need to clear that up… It seems that mimic is installed on the big partition and is working there even with the non-symlinked mycroft-core is the one where my custom skill is working… a mess.

…it still would be good to know where the main Debug Log is stored so Im not locked into using the cli-client where I cant search or copy multiple pages…

Okay , also a bit confused as to why duplicate skills are in both /opt/mycroft/skills and ~/mycroft-core/skills? It seems I should be editing the one in /opt according to the reply above, but then this must be synced into the /mycroft-core when loaded, because it does have my latest edits… Okay this must be directly symlinked, as it is reflecting changes made to dir names. …I see the whole skills dir is. (I dont know why devs insist on putting files all over the place… in the hopes that another user with their own Home dir doesnt want to install their own software? Even still symlink the other way, if that it the case… anyway, I digress).

Currently working on this error:

repeat = re.sub('^.*?' + message.data['Speak'], '', utterance)#                                                                    
KeyError: 'Speak'

Code was copied from https://github.com/MycroftAI/skill-speak/blob/20.02/init.py

I think the ‘Say’ vocab is using a different Skill, because when I change the names of both Skill-speak which I cloned from github and the mycroft-speak.mycroft, the command still works somehow. This leads me to believe I would get this same KeyError if I could trigger Skill-speak.

Yeah, changed the trigger vocab in Speak.voc for that skill and not triggering. Tried to activate the skill again, tried restarting all services, tried touching that skill ini.py and skill not triggering.

OH, for F’s sake, why limit the amount of edits?? Is this really hurting anybody as I record my troubleshooting process?? Come on… I guess Ill have to switch to github where they dont have silly arbitrary whining complaints… was trying to keep this in the community forum, but I guess not… I hope thats just a Discourse thing, with a limit that only an exited dev like me could hit. I’ve been working on voice computer control off and on for a few years, and after moving to Ubuntu, there was nothing very promising until this.

re my comment from above: "EDIT: Aha! I found I had hastily exited out of the mycroft-config edit user Vim window and it was stuck running in the background… …Well, the cli-client is loading (logging) normally, "

It turns out the config file left open is because the usual way to close Nano editor (ctrl-x) is disabled in View Mode while looking at the config for Default using mycroft-config edit Default. This causes the cli-client not to show the starting up portions of the logs.

After ironing out some symlinks to installation directories to larger partitions than my main install and home directory, Im still not able to get my custom skill running, although it does say it is ‘loaded’ and it does work when I do use the non-symlinked ‘mycroft-core’ directory (but then my Mimic installation isnt accessible).

@forslund Im currently getting two errors that may be unrelated, but am trying to resolve anyway:

2020-06-06 14:31:37.804 | WARNING | 4329 | mycroft.api:check_remote_pairing:531 | Could not get device info: PermissionError(13, 'Permission denied')

2020-06-06 14:31:38.006 | INFO | 4329 | mycroft.messagebus.load_config:load_message_bus_config:33 | Loading message bus configs

Ive removed all of the User Config I had included to block connection to mycroft.ai (from the link below) and restarted all services but no luck.

Any advice on how to track those down?


EDIT: These error lines below occur in the bus.log file first thing on startup. I’m thinking its probably a permissions error, but Ive already chowned the entire mycroft-core dir, and dont know which straggler file would be causing this. I will try the config files…

2020-06-06 14:40:35.786 | INFO | 4929 | __main__:main:38 | Starting message bus service...

2020-06-06 14:40:35.789 | INFO | 4929 | mycroft.messagebus.load_config:load_message_bus_config:33 | Loading message bus configs

2020-06-06 14:40:36.230 | WARNING | 4929 | mycroft.api:check_remote_pairing:531 | Could not get device info: PermissionError(13, 'Permission denied')

Well, just before I renamed all the directories for a new install, I thought to try using the dev_setup.sh again, and it resolved the permissions error.

Yep, all errors resolve, except this Stock-skill error that has been there since install. Custom skill still not working yet.

16:00:30.332 | ERROR | 13269 | mycroft.skills.skill_loader:_create_skill_instance:231 | Skill __init__ failed with Exception('Skill has been disabled by Mycroft',) Traceback (most recent call last): File "/media/abc/Iprogs/mycroft-core/mycroft/skills/skill_loader.py", line 228, in _create_skill_instance self.instance = skill_module.create_skill() File "/opt/mycroft/skills/mycroft-stock.mycroftai/__init__.py", line 127, in create_skill return StockSkill() File "/opt/mycroft/skills/mycroft-stock.mycroftai/__init__.py", line 87, in __init__ raise Exception('Skill has been disabled by Mycroft') Exception: Skill has been disabled by Mycroft 16:00:30.338 | ERROR | 13269 | mycroft.skills.skill_loader:_communicate_load_status:287 | Skill mycroft-stock.mycroftai failed to load

@forslund, happy to report that after running dev_setup.sh again, it corrected whatever permissions errors there were… I tried doing it manually so I could learn where everything is located and how the files work together, which I have a basic idea of now… and my new custom skill is working… so I can get back to actually programming functionality instead of troubleshooting the installation and setup, yay!

Part of reporting all of the errors on this forum page is for anyone else searching on those errors to maybe find some ideas for a solution.


working example of a CLI Command Skill here: https://github.com/MycroftAI/mycroft-core/issues/2600