Commit Graph

546 Commits (631875d9c2518ac33ac59b18dadc4dea393dec3b)

Author SHA1 Message Date
Steve Penrod 2424fd1c9b Change to "save_utterances" instead of "record_utterances"
Change to match the documented and more intuitive name "save_utterances",
but add backwards compatibility code to support the original
"record_utterances".
2019-02-11 01:53:28 -06:00
Åke a94019a8b8 Use language set in mycroft configuration (#1925)
Slight refactoring to accommodate for this in a nice way. Created
function connect_to_mycroft() handling fetching the config and
connecting to the mycroft messagebus since these are related and the
order is important to maintain for it to work.
2019-01-31 01:38:47 -06:00
Åke 267c7bf571 Single viseme message (#1973)
* Add new api command to send visemes as single list.  This allows more efficient use of the messagebus and gives implementors flexibility in how they handle the visualization.

* Switch mark1 to use viseme_list
2019-01-31 00:37:55 -06:00
Åke 9ef95506d0 GUI update number 6 (#1964)
* Add communication from GUI to skills

- "set" events from Qt will set/update a variable in the skills .gui member
- It's possible to add general event handlers using self.gui.register_handler()
- Moved registration of skill_id to just after skill init

* Ensure that simultaneously writes doesn't occur

Wrap WebSocketHandler.write_message() with a lock in an attempt to handle "buffererror: existing exports of data: object cannot be re-sized."

* Add better logging to help debug disconnect issue

* Allow overriding the idle page

SkillGUI.show_page() and SkillGUI.show_pages() now takes an optional
override_idle parameter. This is used as a hint by the mark-2 skill
and if possible the idle screen will not be shown.

* Improve debugging using Logger

* Raise exception when sending a non-existing gui page

* Restore running state to new connections

When a GUI is connected data and running namespaces are synchronised and
shown.

This refactors the code quite a bit moving the GUI state from the GUIConnection
object to the Enclosure.

The GUIConnection object does the handles the sync in the on_connection_open()
method.

* Add gui.page_interaction message

Currently triggered on page change on the display.

* Handle message when gui changes sessionData

* Check if socket exists on gui before sending data

* Increase port on each failure and retry
2019-01-22 08:45:19 -06:00
Alistair Francis 71afcb9ce5 text_client.py: Don't log stack trace on missing conf (#1957)
If we are missing the ".mycroft_cli.conf" file we print a message to the
user informing them that we are ignoring the missing file along with a stack trace. The stack trace is really not necessary so this removes it.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-01-18 09:59:55 +01:00
Steve Penrod b38668a2ef Fix Ctrl+C handling in CLI
Ctrl+C was not being properly handled by the CLI, resulting in an  unclean
shutdown and other unexpected consequences -- e.g. a
"./start-mycroft.sh debug" would kill the background processes on exit.  The
KeyboardException was never being triggered.

Now the SIGINT is being captured and Ctrl+C behaves (as intended) just like
pressing Ctrl+X.
2019-01-17 09:47:43 +01:00
Åke Forslund 38701a9790 Remove inheritance from object
Inheriting from object isn't necessary in python3.
2019-01-11 09:24:21 +01:00
Åke fa5c9abd78 GUI Cleanup (#1939)
* Try to improve stability

- Remove sync_active
- Update the way variables are sent to the gui

* Do not show full path for pages

The cli now shows the basename of the current page to make it easier to
determine if the correct page is displayed.

* Make elements in loaded list named tuples

This makes the intent of the code a bit cleaner.
2019-01-09 20:09:21 -06:00
Åke Forslund ff04af99c9 Move the device finding code into an util function 2019-01-08 08:05:07 +01:00
Steve Penrod 2557637591 Support selecting microphone by name
Normally Mycroft will use the default PortAudio input device as the
microphone input for the user.  However in some cases there is reason
to specify a different input.

The "device_index" under the "listener" section in mycroft.conf has
always allowed a user to select the microphone explicitly.  But on
some systems the indices can change from reboot to reboot.  So this
adds the "device_name" setting.  If it exists (and the "device_index"
has not been specified explicitly), a regex match will be run against
the PortAudio device names.

When "device_name" is used, the voice.log will contain a listing of
the devices as they are tested.  This can be used to debug if a
name isn't matching as expected.

EXAMPLES:
/etc/mycroft/mycroft.conf
```
{
    "listener": {
        "device_name": "aawsrc"
    }
}
```
Would find a match against "aawsrc" or "aawsrcplug".  To force a specific
match, you can use a regex such as "aawsrc$".

/etc/mycroft/mycroft.conf
```
{
    "listener": {
        "device_index": 2
    }
}
```
The PortAudio device index specified will be used.

Names and indexes for PortAudio are difficult to guess.  The simplest way to
view them is either enter a value for "device_name" and look at the names
which appear in the log when starting Mycroft, or to run a simple program
such as:
```python
import pyaudio

pa = pyaudio.PyAudio()
for i in range(pa.get_device_count()):
    dev = pa.get_device_info_by_index(i)
    print((i, dev['name'], dev['maxInputChannels']))
```
2019-01-08 07:51:41 +01:00
Åke 2e9d764d36 GUI update (#1922)
Several additions to the GUI protocol support

These changes allow switching between pages successfully with the current
mycroft-gui widget:
* Optimized commands to handle the active skill list
* MycroftSkill.gui.show_pages(list, idx) allows multiple-pages to be displayed
  at a time starting with the given index visible.
* Merge SkillGUI.show_page with show_pages
  This limits code duplication and makes things a bit more maintainable.
* Do not reload on changed .qmlc files
* Make EnclosureGeneric derive from Enclosure
* Update show function to match mycroft-gui-app
  - adds internal representation of all loaded skills
  - uses new commands to switch between pages and namespaces
* Add Extra debug output in enclosure
  - Log if starting websocket fails
  - Log the sending of page info in more detail
* Update GUI Debug client in CLI
  - The CLI GUI now handles the new messages for switching pages
  - Handle different data types better by using format instead of string concatenation
* Disable syncing code.
  The sync code at startup outdated and needs to be reworked. Disabling it for now
  to allow better interaction.
* Minor cleanups
  - do not inherit from object
  - use format instead of string concatenations
  - remove duplicated self.loaded
  - correct private member access
* Refactor GUIConnection.show()
   Move the actions into separate methods for better overview of the logic
* Flipped "valid_file" to become "ignored_file"
2018-12-29 21:35:48 -06:00
Steve Penrod 1427992c99 Add basic barge-in functionality
The ability to "barge-in" has been lacking from Mycroft Core.  The Mark 1
microphone was unable to support this due to physical limitations, but the
Mark II and other implementations with more advanced mic tech which can
hear over themselves are able to continuously listen.

To enable this while retaining backwards compatibility with simpler mic.py
systems, there are now two mycroft.conf values:

{
   "listener": {
        "mute_during_output" : true,
        "duck_while_listening" : 0.3
   }
}

The above values are defaults, and implementers will likely override them
using the /etc/mycroft/mycroft.conf file when appropriate.

The duck_while_listening setting is currently handled in Mycroft's
skill-volume.  The mute_during_output is handled within mycroft-core itself.
2018-12-28 18:12:42 -06:00
Åke Forslund 3175baa2eb Stop hotword engines during reload
- Add overridable stop() method to HotwordEngine Class
- Add stop implementation to precise shutting down the runner
- Call wakeword_recognizer.stop() before reloading the listener configuration
2018-12-07 13:28:47 +01:00
Åke Forslund f95ff0a2f3 Remove extra except.
except except Exception -> except Exception
2018-12-05 12:36:53 +01:00
Steve Penrod 1e5ff1392f Feedback from code review
Several small changes based on the code review feedback:
* Drop '_' from classes like Enclosure_Mark1
* Adopt Python 3 style for class definitions and don't explicitly list '(object)'
* Slightly better documentation
* Moved MycroftSkill.show_html() to SkillGUI, resulting in code like self.gui.show_page('Weather.qml')
* Renamed SkillGUI.__dict to SkillGUI.__session_data.  This better reflects the
  how values are accessed in the QML.
2018-12-05 01:40:43 -06:00
Åke Forslund 70655bd9b6 Handle missing "enclosure" section in system config
Default to empty dict instead of None if the "enclosure" section is missing
2018-12-05 07:53:35 +01:00
Steve Penrod 07bd6ef7af Code cleanup
Fixing PEP8 and such before merging into 'dev' branch.
2018-12-03 17:33:26 -06:00
Steve Penrod 0ff744529b * Add tracking of the active namespaces for the GUI. Currently the namespace list
is kept in order, but old namespaces/skills are never culled.
* The active namespace list is synced on a GUIConnection level
* QML display requests now are sent as a list instead of a single entry, i.e.
  with "gui_urls" instead of "gui_url".  Currently a skill can only send a single
  QML, however.
* Change CLI GUI client to handle "gui_urls" instead of "gui_url"
2018-11-30 03:04:53 -06:00
Steve Penrod 685a729994 Enhance CLI GUI client
The GUI client built-in to the CLI now has these features:
* Activate/deactivate via Ctrl+G
* GUI 'window' shows active page title and all namespace variables
* Add fool-proof primitive draw(x,y, msg) that takes care of clipping, and padding
2018-11-23 09:29:16 -06:00
Steve Penrod b9fb463727 Fleshing out GUI mechanisms, CLI "GUI"
Further fleshing out of the GUI mechanisms
* Support for data and page from Mycroft -> GUIConnection
* Add a 'reconnecting' event for the messagebus
* Add MycroftSkill.show_url()
* Plumb MycroftSkill.gui into the messagebus
* Implement MycroftSkill.gui dictionary

CLI extensions for the GUI:
* Can now act as a simple GUIConnection
* Minor revamp of messagebus connection, provides kinder handling when
  messagebus isn't found or ready.
* BUGFIX: An empty filter would filter ALL messages
* BUGFIX: Input wider than the screen would cause a crash
* BUGFIX: "filter" or "find" with no param would filer "filter" or find "find"
2018-11-21 02:05:28 -06:00
Steve Penrod dbd3675156 Fixing a few bugs and adding test code to fire up a weather skill visualization upon GUI connection.
Still very much a work in progress.

For understand and testing, here is the sequence:

STEP 1:  GUI announces itself
* Connect to the main Mycroft messagebus
* Send:  "mycroft.gui.connected" with data { "gui_id": XXX } where XXX is a uniq ID (uuid)

STEP 2:  Mycroft creates GUI socket
* Mycroft extracts the gui_id
* Mycroft prepares a socket and announces its availability on the Mycroft messagebus with:
        self.bus.emit(Message("mycroft.gui.port",
                              {"port": self.GUIs[gui_id].port,
                               "gui_id": gui_id}))

STEP 3:  GUI connects
In python, a very minimal test socket handler on the GUI side would look like this

  from websocket import create_connection

  port = 18181 (from the message above)
     ws = create_connection("ws://0.0.0.0:"+port+"/gui")

  ws.send("Hello, World")
  print("Sent")
  print("Receiving...")
  result =  ws.recv()
  print("Received '%s'" % result)
  ws.close()
2018-11-07 11:06:57 -06:00
Steve Penrod aede71db86 First pass at support for the Qt/QML display:
Enclosures
* Create a mechanism to instantiate unique Enclosure classes, depending on the platform found in the SYSTEM mycroft.conf
* Implement a generic Enclosure, which support the new GUI protocol
* Implement a Mark 1 Enclosure (expects the serial connection to an Arduino)
* Implement the start of a Mark II enclosure
* Implement a generic enclosure (no screen)
* Implement the GUI announcement and protocol basics

MycroftSkill
* Implement the basis of the GUI-controlling interfaces.  Namely:
  - MycroftSkill.show_text()
  - MycroftSkill.show_image()
  - MycroftSkill.show_html()
  - MycroftSkill.show_page()
  - MycroftSkill.gui to set values for page displays.

Configuration
* Add "gui_websocket" to the mycroft.config.py
2018-11-06 01:48:16 -06:00
Steve Penrod 0d64e78d0c Add protection for naive skill authors (#1825)
* Add protection for naive skill authors

It is fairly common for new skill authors to attempt actions in the __init__()
method which are not legal yet, as the Skill has not been fully connected to
the Mycroft system.  This adds an @property protection layer for the two most common
issues:
* Accessing MycroftSkill.bus
* Accessing MycroftSkill.enclosure

Now those are properties instead of variables and provide appropriate warnings
when used before they exist.

Also enhancing the handling of error logs in the CLI to highlight problems such
as this:
* Color "- ERROR -" log messages in red
* Retaining leading characters from log messages, improving readability in formatted messages
2018-10-01 21:41:48 +02:00
Steve Penrod 2efe3eb9ef Fix Ctrl+C and Ctrl+X in CLI (#1826)
* Fix Ctrl+C and Ctrl+X in CLI

There were several quirks in the shutdown of the CLI client:
* Consumed Ctrl+C wasn't being handled cleanly
* main() got called twice, requiring two Ctrl+Cs to exit
2018-09-30 11:14:40 +02:00
Matthew Scholefield a29d00707d Check for a Precise model automatically for custom wake words 2018-09-26 11:14:15 -05:00
Matthew Scholefield c6f9513e9d Allow local model file in precise 2018-09-04 22:59:52 -05:00
Dominik de0bf7d0fd Fix for broken communication with Arduino 2018-09-03 14:50:51 +02:00
Åke Forslund a86359da7f Fix Åkeisms in the code
Updated renamed variables reference everywhere where they were used
2018-08-30 17:10:17 +02:00
Åke 80a37ec46a Move Mark-1 specific image code from api to mark-1 enclosure (#1767)
* Fix removing of the active user

* Move image drawing routines to enclosure client
2018-08-28 14:50:03 -05:00
Åke 85ae69597b Separate enclosure api from enclosure client (#1760)
This is a step towards abstracting the idea of an Enclosure which ties Mycroft to the hardware that is running Mycroft.

- Move the enclosure API to mycroft.enclosure.api (previously was mycroft.client.enclosure.api)
- Move display_manager out of enclosure client to mycroft.enclosure.display_manager
- Merge EnclosureWeather into EnclosureMouth
- Wrap display manager in a class
2018-08-27 13:44:12 -05:00
Åke 0d14e01907 Fix skills listing in CLI (#1759)
Skills list shared the help screen id it was immediately overwritten by
the help.

- Give the skills page a separate page number
- Replace screen id numbers with simple identifiers
- Add simple handling of multiple pages
2018-08-24 00:03:32 -05:00
Åke 64476eb143 Replace emitter/ws with bus (#1757)
Makes the code a bit more understandable
2018-08-21 20:50:50 -05:00
Åke Forslund b41d9edc13 Split text client from __main__
- __main__.py keeps the main setup of hiding stderr/out and argument parsing
- text_client.py contains the actual text client
2018-08-16 20:54:05 +02:00
Åke Forslund a66e23d8ab start processess using python -m
- rename process main.py to __main__.py
- update start-mycroft.sh/stop-mycroft.sh scripts to reflect the change
2018-08-16 15:21:22 +02:00
Åke 13f669d514 Set default encoding in a cleaner way (#1745)
- simplify code setting LC_ALL
- Handle other encodings than utf-8
2018-08-15 17:16:34 -05:00
Steve Penrod 2e873e43bf Change to the supported wait_while_speaking() (#1743)
Code was using the deprecated version from mycroft.util instead of
the mycroft.audio version.
2018-08-15 10:35:50 +02:00
Steve Penrod 46c92e0c36 Fix CLI lockup; simple 'speak' support; help display
Several minor and simple CLI fixes:
* The CLI was locking up with at Lock() deadlock when rebuilding the
  filtered log.
* The simple_cli() wasn't registering handle_speak() on the websocket,
  even though the handler was setup for it.  The utterances are already
  clear from the Input: line or from the logs being printed, so no need
  to have a handle_utterance() registered in the simple_cli() case.
* Help wasn't refreshing the screen, so was invisible.
* An error could be thrown if Ctrl+Z was hit to suspend the 'fg' to
  return to foreground before any key was pressed.
2018-08-14 22:40:08 -05:00
Steve Penrod 1c82945576 Move logs to /var/log/mycroft/ directory
Simplifies permissions and future log-rotations to have all logs
under a single folder instead of having to give permissions to each.
2018-08-02 23:57:13 -05:00
Steve Penrod f329051743 Move logs to /var/log in all cases
Previously, the location of the log files changed depending
on whether you were running on a Mark1/Picroft or under a
"Github" install.  Now they are always under the same directory
at /var/log/mycroft-*.log

This also updates the CLI to pull from that location always.

Additionally:
* Removed the nonfunctional 'wifi' option from start-mycroft.sh
* Made the validation for dev_setup.sh exit instead of just show
  a warning message in start-mycroft.sh
* Added code to allow dev_setup.sh to be run from different
  directories successfully
2018-08-02 21:21:30 -05:00
Steve Penrod 040b64d09d
Fix CLI screen corruption (#1704)
The CLI would often have temporary screen corruption.  This reworks
several things to correct that issue, although it looks like the
ultimate cause was drawing to the screen while in the middle of
waiting on a VT100 ESC keycode sequence.

* Rearchitected all screen drawing to run in a single thread.  Now
  call set_screen_dirty() instead of draw_screen()
* Added a lock on accessing the various Log buffers, preventing
  changes to the buffer in the middle of a redraw
* Modified key reading logic when ESC character is received.  Now
  uses a 1 second timeout if no subsequent keycodes are sent
* Catch several special exceptions.  Curses throws exceptions in some cases during get_wch(), such as
when you Ctrl+Z suspend the CLI the resume the process.  Also moved Ctrl+C processing into this exception handler.
2018-07-30 17:17:48 -05:00
Steve Penrod 223c88b4dd CLI Updates: Restore VT100 support, help, etc. (#1667)
* Restored VT100 function key support
* ESC now clears the entry line
* Spoken commands now become part of the history
* Enhanced help screen with auto word-wrap
* Bugfix: "Show meter" setting didn't persist, now it does
2018-07-12 09:38:29 +02:00
Matthew Scholefield 189e0f10ab Refactor Precise engine and support engine timeouts 2018-07-06 00:05:28 -05:00
Steve Penrod 17aab53fae Enhance the behavior of the Mark 1 button (#1668)
The Mark 1 button press can now be "consumed" when a skill handles
the Stop command.  When this happens, the button press will not
trigger listening mode.  An additional press would be needed to
trigger listening.

This introduces the "mycroft.stop.handled" messagebus message.  It
carries a data field called "by" which identifies who handled it.
Currently the values are "TTS" for when speaking ends or the name
of a skill which implements Stop and returns True from the call.

Also fixed a potential bug when the flag to clear queued visemes
was left set after a button press.
2018-07-05 20:56:54 +02:00
Aditya Mehra 3ae4746099 Feature add query mic status (#1656)
* Feature: Add query mic status

Adds the message bus message `mycroft.mic.get_status` which responds with data on if mic is muted or not.
2018-06-27 15:51:33 +02:00
Åke b1408617bc CLI Feature: skill commands (#1612)
* Update format for skill listing

Now send the skills with id and active status

* Add commands to activate/deactivate skills

* Add "unload all except one" functionallity

* Update after rebasing

- fix identifying skills

* Unload skills if they're removed from disk

* Rename _shutdown to default_shutdown

The method is not intended to be non-public, and this should shut up
codacy bot.

* Handle keep command without argument

* Add new commands to help

- Split help into multiple pages as needed

* Support :activate all
2018-06-22 00:59:51 -05:00
Åke 5d6fd4d871
Merge pull request #1629 from MycroftAI/feature/https-ww-upload
Change wake word upload to https request
2018-06-07 08:58:28 +02:00
Åke b57a0ddb65 Use get_wch() to support unicode input in the CLI (#1609)
The CLI interface should now allow non-ASCII characters, including those used in non-English languages.
2018-06-06 17:02:48 -05:00
Matthew D. Scholefield 727e1c787c Change wake word upload to https request
Also strips out old alternative ways to enable wake word upload
The logic for uploading wake words is now:
 - Only if opt-in is enabled
 - With an additional "disable" setting to selectively prevent it
2018-06-06 14:53:11 -05:00
Matthew D. Scholefield 8c0b471d24 Fail wake word upload on first try
Previously failed wake words would collect and each one would attempt an upload and fail. Now, this does the same process but failing on the first wake word that fails to upload
2018-05-15 12:31:06 -05:00
Matthew D. Scholefield 3fa958cbac Make scp upload quiet and reduce saved seconds
The scp upload shows the account id which isn't the best to put in logs
The saved audio seconds used to contain audio before so that it could be used to identify multiple recordings that didn't activate the device. However, we've since moved to tagging only the last 3 seconds
2018-05-15 12:28:28 -05:00