MycroftAI / mycroft-core

Mycroft Core, the Mycroft Artificial Intelligence platform.
https://mycroft.ai
Apache License 2.0
6.51k stars 1.27k forks source link

Central Issue for porting to windows #2627

Closed NoamDev closed 1 week ago

NoamDev commented 4 years ago

This a central issue for discussions about porting Mycroft to windows. cc @el-tocino

NoamDev commented 4 years ago
NoamDev commented 4 years ago

I installed the fann2 from the link above (actually though pipwin). Then tried to move on, I changed the paths in the configuration, replace '~' with %USERPROFILE% and opt/ with %APPDATA%. After that I ran python -m mycroft.messagebus.service. I had to replace '/tmp' somewhere with a cross-platform equivalent. Now I found that SIGKILL is unix specific and in windows it should be done a little differently, but since process killing doesn't sound important as long as everything works as expected, I removed it for now. message bus seem to work.

forslund commented 4 years ago

Nice!

Shouldn't ~ work?

>>> from os.path import expanduser
>>> expanduser('~/hello')
'C:\\Users\\afxxu3/hello'
>>>
NoamDev commented 4 years ago

Oh cool! I wasn't aware of that.

NoamDev commented 4 years ago

windows does not like to connect to 0.0.0.0 (though listening is not a problem) so the config should be changed here to 127.0.0.1

NoamDev commented 4 years ago

Oh, a problem, maybe. python didn't understand %appdata% and %userprofile% and instead created directories with those names.... I can change the second to ~, for now, I'll change the first to something harmless.

forslund commented 4 years ago

Haven't tried this but maybe the code should be updated to use os.path.expandvars as well as expanduser. at some point.

NoamDev commented 4 years ago

Is there a way to disable some skills? Deleting them just cause them to be re-dowbloaded.

forslund commented 4 years ago

You can add them to the list of blacklisted_skills

Edit: they will still be downloaded but won't be started.

NoamDev commented 4 years ago

Thanks, that's sufficient. I had to also add os.path.normpath in skill loader, but it works.

NoamDev commented 4 years ago

Do you know of windows builds of mimic? Some binary releases? I have a ubuntu dual-boot, so I'm technically able to cross-compile, but I'd prefer to save the time...

NoamDev commented 4 years ago

Btw, I have skills service up and runing now:)

forslund commented 4 years ago

No mimic windows exe pre-built I'm afraid. You can skip local mimic for the time being and use the Mimic2 (American Male selection on home.mycroft.ai)

NoamDev commented 4 years ago

But I can't pair it since the code should be spoken... Is there another way of getting a pairing code?

forslund commented 4 years ago

It will be written in the log output. Look for Pairing code: <CODE>

NoamDev commented 4 years ago

Wait, I'll try anyway. Maybe ot writes it too.

NoamDev commented 4 years ago

After some workarounds with curses, I have text interface. However, I can't pair, right after function handle_pairing is finished the pairing-skill is being removed..

2020-07-01 18:18:31.521 | INFO     |  7856 | mycroft.skills.padatious_service:train:102 | Training complete.
2020-07-01 18:18:31.528 | INFO     |  7856 | mycroft.skills.padatious_service:train:106 | Mycroft is all loaded and ready to roll!
2020-07-01 18:18:31.733 | INFO     |  7856 | mycroft.skills.skill_manager:_unload_removed_skills:322 | removing mycroft-pairing.mycroftai
2020-07-01 18:18:31.770 | INFO     |  7856 | mycroft.skills.skill_loader:_execute_instance_shutdown:147 | Skill mycroft-pairing.mycroftai shut down successfully
2020-07-01 18:18:31.773 | INFO     |  7856 | mycroft.skills.skill_manager:_unload_removed_skills:322 | removing mycroft-volume.mycroftai

So the pairing code though retrieved, is never spoken, and even if print it, there's no one left to listen, as the skill is being removed.

forslund commented 4 years ago

There's probably some issue in the code checking if a skill has been deleted. Check this method, if something is too isn't adding up: https://github.com/MycroftAI/mycroft-core/blob/dev/mycroft/skills/skill_manager.py#L313

NoamDev commented 4 years ago

Well, it somehow got solved. 🤷‍♂️ But that doesn't mean I have audio of course... I find that many packages are missing. Probably a tradeoff of not runing an installation script.

ChanceNCounter commented 4 years ago

I applaud the effort and apparent progress, but I figure I should nevertheless paste the counterargument from chat:

it's dependency hell for days. the nature of python on windows means that many stories end in, "just isn't gonna work cross-platform like that."

WSL is a promising solution, because it provides the necessary compatibility layer between headless *nixware and Windows itself. however, it's still at a stage where they really don't want you to dick with windows from within WSL, apart from launching programs, and i've discovered several times that you can trigger opaque, generic BSODs when you try.

i'm convinced at this point that the best way forward for a windows port is to wait until system control via WSL is more thoroughly supported, and less prone to crashes. if you don't try to control the system, mycroft already runs almost-natively under WSL, if you install pulseaudio on windows.

it may be possible to create a windows-native message bus listener, run mycroft itself under WSL, and write a whole separate windows client that responds to the message bus. i haven't pursued that because it's such a clunky solution. be great for you and for me, but for consumers? yeesh.

On the other hand, I am very optimistic about Mycroft under WSL, assuming WSL catches up. Right now, everything works out of the box with WSL+PulseAudio. You just can't do any system control tasks, launching programs, stuff like that. Just caching directory contents in a skill has caused bluescreens. But, if all you wanna do is interact with Mycroft, Q&A skills, control IoT devices, things like that, WSL will do fine.

ChanceNCounter commented 4 years ago

Oh, and, naturally, no X = no GUI =P but Jarbas' TUI works well.

NoamDev commented 4 years ago

@ChanceNCounter It's not gonna be easy, but I believe it has to be done that way.

NoamDev commented 4 years ago

I don't understand why if audio service loads services like vlc, it uses the audio utils for tts instead.. When does it use the audio services?

forslund commented 4 years ago

It's made to be a pluggable system for different audio libraries to perform audio playback. This is used for example by skills playing news or a playlist of media.

These are loaded as they are available and none is a hard requirement. the "simple" uses the basic playback commandlines defined in the configuration (starting on L53). And can be overridden in any of the system or user configurations.

VLC will be used if it is installed since it offers better handling than the "simple" systems, etc.

These services aren't needed for speech or anything I wouldn't focus on them in the beginning. Finding replacement commandline applications to use to render speech (play_wav and play_mp3 in the configuration)

NoamDev commented 4 years ago

Ok, for now I use ffplay. It's nice:) Do you think it's time to fork and start coding?

forslund commented 4 years ago

Haven't you already? ;)

NoamDev commented 4 years ago

Is there anything holy with the fann2 version? Why not use 1.1.2?

NoamDev commented 4 years ago

Ok, I started to make it more organized, beginning with requirements installation script. I created this pr to allow others to participate.

krisgesling commented 4 years ago

Hey, got your CLA Thanks!

In terms of requirement versions. Most of the time it's what was latest and working at the time the code was committed. As this code regularly gets pushed out to many thousands of devices we keep the dependency versions very specific. We update periodically, but particularly if there is an issue, security update, or a new feature is available that we need.

In saying that a relaxed dependency environment variable recently got added which you might be interested in: https://github.com/MycroftAI/mycroft-core/pull/2562

NoamDev commented 4 years ago

The PR current code works with messagebus and skills. (However it currently uses an unofficial build of fann2, we should fork and build one for ourselves.)

The next thing is the text client, it depends on curses which does not support windows. The way I see it we have 2 options:

Unless you there's a better solution, can any one take migrating to UniCurses on himself?
I already forked it from sourceforge here: https://github.com/NoamDev/pyunicurses.

cgohlke commented 4 years ago

use an unofficial build from http://www.lfd.uci.edu/~gohlke/pythonlibs/ (I don't think we should do that, and we don't have the source code to build by ourselves)

The source code is available on that site and there are forks available on PyPI and GitHub

NoamDev commented 4 years ago

Nice to meet you here 😊

forslund commented 4 years ago

Awesome progress, gonna try getting it running this weekend and see if I can provide a mimic executable for you.

For fann2, We do have a fork here: https://github.com/MycroftAI/fann2-update, it has some fixes for multi-arch issues on linux. We never pushed a package since it was mainly I who had issues with it...

Maybe the windows fixes can be added to that?

NoamDev commented 4 years ago

I think the best way would be to publish wheels for fann2 on pypl. As windows does not come with swig and cmake. @cgohlke did you have to make changes to the code? May we request your help in case we have a problem in doing so?

cgohlke commented 4 years ago

did you have to make changes to the code?

I used my own setup.py to also compile the FANN-2.2.0 library source and ran swig manually. E.g. this might work:

diff --git a/setup.py b/setup.py
index 37af7c7..5c478b4 100755
--- a/setup.py
+++ b/setup.py
@@ -88,8 +88,12 @@ def build_swig():
     swig_cmd = [swig_bin, '-c++', '-python', 'fann2/fann2.i']
     subprocess.Popen(swig_cmd).wait()

-if "sdist" not in sys.argv:
-    build_swig()
+#if "sdist" not in sys.argv:
+#    build_swig()
+
+srcdir = "../FANN-2.2.0-Source/src/"
+sources = [srcdir+src for src in
+               ('fann.c', 'fann_cascade.c', 'fann_error.c', 'fann_io.c', 'fann_train.c', 'fann_train_data.c')]

 setup(
     name=NAME,
@@ -120,11 +124,12 @@ setup(
     include_package_data=True,
     packages=find_packages(),
     py_modules=['fann2.libfann'],
-    ext_modules=[Extension('fann2._libfann', ['fann2/fann2_wrap.cxx'],
-                           include_dirs=['./include',
-                                         '../include', 'include'],
-                           libraries=['doublefann'],
-                           define_macros=[("SWIG_COMPILE", None)]
+    ext_modules=[Extension('fann2._libfann', ['fann2/fann2_wrap.cxx'] + sources,
+                           include_dirs=['./include', srcdir+'include', '../include', 'include'],
+                           #libraries=['doublefann'],
+                           define_macros=[("SWIG_COMPILE", None),
+                                          ("WIN32", None),
+                                          ("FANN_NO_DLL", None)]
                           ),
                 ]
 )
swig.exe -c++ -python -I..\FANN-2.2.0-Source\src\include  fann2\fann2.i
NoamDev commented 4 years ago

Assuming all checks pass now, we have text client working (using windows-curses). During my work, I noticed Ctrl+C did not trigger a SIGINT handler.. At least not while curses was running. We should make sure one day that it doesn't influence other places where we subscribe to SIGINT, like the mycroft.lock module.

NoamDev commented 4 years ago

We now have audio as well, though my lightweight windows setup won't install mimic1. For now, you have to use the text client and set up pairing first. Then you can configure it to use mimic 2 in https://home.mycroft.ai. Also, for now, ffplay is used as the command-line audio player. Are there built-in windows alternatives? Alternatively, when we have a proper installer it can install ffplay too. (65 MB). If anyone tries this, I'd like to hear whether yo think ffplay is a proper alternative to what's used in linux. One last thing, mimic2 sometimes times out. Because there is no mimic to fallback to, it'll log stack traces and it won't answer you, but won't crash.

NoamDev commented 4 years ago

For fann2, We do have a fork here: https://github.com/MycroftAI/fann2-update, it has some fixes for multi-arch issues on linux. We never pushed a package since it was mainly I who had issues with it...

Maybe the windows fixes can be added to that? @forslund We need to build wheels, can we have a ci with a windows machine?

krisgesling commented 4 years ago

Yeah if we're going to have a Windows release then we definitely need CI setup for it.

TBH I don't want to invest too much time in doing that until we've ironed out the bugs and can get a Windows version running manually. It does sound like you are making some excellent progress though!

Are you using the changes suggested by cgohlke to compile your own currently?

NoamDev commented 4 years ago

I was able to compile fann2 according to cgohlke's insturctions. Though I haven't tested it with mycroft yet. About pushing it to https://github.com/MycroftAI/fann2-update, this setup is windows only, so.. it would mean @forslund won't be able to use it for his own problem. Anyway, I think it's best to create another fork named fann2-windows. I'll create one.

NoamDev commented 4 years ago

You can now install fann2-windows using pip install git+https://github.com/NoamDev/fann2-windows.git on a windows machine that has swig in its path. I didn't bother making it cross-platform. There is some dead code in setup.py.. and package details should also change, I guess. But it's not very important right now. I still need to make sure it works with mycroft, maybe later.

NoamDev commented 4 years ago

if I understand correctly the only dependent of fann2 is padatious. Is padatious on by default? If not, I'm not sure how to verify whether my installation actually works. https://mycroft-ai.gitbook.io/docs/mycroft-technologies/overview:

Adapt is the default intent parser for all Mycroft platforms.

krisgesling commented 4 years ago

Ah I should update that - both Adapt and Padatious are available by default

krisgesling commented 4 years ago

Just had to go check, but asking Mycroft "how are you" should use Padatious

NoamDev commented 4 years ago

I checked now, it works:) I commited my changes, so now the pr does not depend anymore on cgholke's builds. Only pypl and my git repo (for now).

NoamDev commented 4 years ago

@forslund Have you tried producing mimic builds?

krisgesling commented 4 years ago

I think I'm going to buy my first Windows key in about 15 years because of this :smile:

NoamDev commented 4 years ago

😂 I PMed you about that.

NoamDev commented 4 years ago

I built mimic using wsl. But beacuse mycroft is looking for file named 'mimic' and not 'mimic.exe'. I'll try to change it so that in windows it'll look for mimic.exe and then see if it works.

NoamDev commented 4 years ago

I did so, and now it works. In addition to mimic1 executable releases, we also need precise releases. I already opened an issue there MycroftAI/mycroft-precise#163. How do you even build precise linux executables? There doesn't even seem to be anything but python there anyway, and setup.sh only calls setup.py after a few preparations..