fossasia / susi_linux

Hardware for SUSI AI https://susi.ai
Apache License 2.0
1.61k stars 149 forks source link

Make an automated support for using either Snowboy or Pocketsphinx when one is not installed. #215

Closed prateekiiest closed 6 years ago

prateekiiest commented 6 years ago

Is your feature request related to a problem? Please describe.

Currently under hotword, we let the user decide if they have Snowboy installed on their device and ask them to use it if they have (due to its much more features). On the other hand if Snowboy is not installed we ask them to go for PocketSphinx and use it.

https://github.com/fossasia/susi_linux/blob/912948bf34eb43018f71fde44e6ff5ea44eaab2a/main/hotword_engine/__init__.py#L7

Instead of this we can easily do it through the code for the user by checking if the corresponding library is available without the user having to bother which hotword detection to import.

Describe the solution you'd like Make a try catch exception while importing the hotword detection library under https://github.com/fossasia/susi_linux/blob/master/main/hotword_engine/__init__.py

https://github.com/fossasia/susi_linux/blob/912948bf34eb43018f71fde44e6ff5ea44eaab2a/main/hotword_engine/__init__.py#L10

A clear and concise description of what you want to happen.

So we can see if we get an ImportError while importing snowboy, then we can import the Pocketsphinx and vice-versa. This will not let the user to bother about which library to used without having him/her to check which one is installed. It would simply try importing the libraries and if exception occurs in one it will go for importing the other module.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered. NA

Additional context Add any other context or screenshots about the feature request here. NA

Would you like to work on this ? I would like to work on it

prateekiiest commented 6 years ago

@stealthanthrax I am unable to add labels without right access. Could you assign me this and add appropriate labels for this issue?

sansyrox commented 6 years ago

@prateekiiest , what if the user wants to user Pocketsphinx by default??

prateekiiest commented 6 years ago

you are saying when both the libraries are installed properly?

we make an exception only when snowboy is not present, then use Pocketsphinx. Else in all other cases use Snowboy ?

sansyrox commented 6 years ago

Right now we provide the user a choice to select from the library, should we continue to do it? @mariobehling @Orbiter @hongquan @cweitat @woshikie . What is your opinion on this??

prateekiiest commented 6 years ago

So under init.py we have

from .snowboy_detector import SnowboyDetector
from .sphinx_detector import PocketSphinxDetector

instead of that

try:
    from .snowboy_detector import SnowboyDetector

except ImportError:
       print('Snowboy Detector is not present')
       from .sphinx_detector import PocketSphinxDetector

try: 
    from .sphinx_detector import PocketSphinxDetector
except ImportError:
   print('PocketSphinx not installed')
   print('We recommend using Snowboy')
   from .snowboy_detector import SnowboyDetector

Some thing like this, without the user to choose.

hongquan commented 6 years ago

If you think Snowboy is better, just let our app use it by default, and fallback to PockSphinx if Snowboy is not available. No need to let user choose.

Don't copy Snowboy and PocketSphix/ to our app folder (https://github.com/fossasia/susi_linux/issues/219#issuecomment-402227526). Just let them stay in their default location (Python's packages folder). You can still detect their availability with import.

prateekiiest commented 6 years ago

@hongquan thanks for your input on this. Can you please elaborate how we can detect that using import? Does the above approach that I mentioned look plausible?

sansyrox commented 6 years ago

@prateekiiest , instead of using from .sphinx_detector use from sphinx_detector

hongquan commented 6 years ago

@prateekiiest

SNOWBOY_AVAILABLE = False
POCKETSPHINX_AVAILABLE = False
try:
    from snowboy.snowboydetect import SnowboyDetect
    SNOWBOY_AVAILABLE = True
except ImportError:
    pass

Note, the symbol looks different (snowboy.snowboydetect.SnowboyDetect vs snowboy_detector.SnowboyDetector) because mine is using standard installation of snowboy.

hongquan commented 6 years ago

Looking into _hotworkengine folder:

image

The snowboy_detector module is the local module of hotwork_engine, so that you have to import by from .snowboy_detector import ... in __init__.py script.

Inside _snowboydetector.py:

import os

from .hotword_detector import HotwordDetector
from .snowboy import snowboydecoder

TOP_DIR = os.path.dirname(os.path.abspath(__file__))
RESOURCE_FILE = os.path.join(TOP_DIR, "snowboy/resources/susi.pmdl")

class SnowboyDetector(HotwordDetector):

It is trying to import snowboy from the local folder (as seen in the screenshot). So, to use the standard installation of snowboy, you have to delete the snowboy folder, and fix the import line in _snowboydetector.py.

prateekiiest commented 6 years ago

Thanks @hongquan for giving a clear view on this. I have sent a PR for deleting the snowboy folder.

hongquan commented 6 years ago

@prateekiiest Which PR is to delete Snowboy? We have 3 things to do:

It will be good if you can combine these to 1 PR, so that it is not half-cooked and break the system.

prateekiiest commented 6 years ago

@hongquan I am only currently deleting the cp operation for moving files. PR #231

I will fix the third point under #228

prateekiiest commented 6 years ago

Currently the things that has been done are follows

I have already merged the patch-2 changes of PR https://github.com/fossasia/susi_linux/pull/231 into PR https://github.com/fossasia/susi_linux/pull/228