Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Python fixes #383

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/Python3/_snowboydetect.so

This file was deleted.

36 changes: 23 additions & 13 deletions examples/Python3/demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import snowboydecoder
#!/usr/bin/env python3
from snowboy import snowboydecoder
import sys
import signal
import os

interrupted = False

Expand All @@ -14,22 +16,30 @@ def interrupt_callback():
global interrupted
return interrupted

if len(sys.argv) == 1:
print("Error: need to specify model name")
if len(sys.argv) != 2:
print("Error: need to specify 1 model name")
print("Usage: python demo.py your.model")
sys.exit(-1)

model = sys.argv[1]
def main():
model = sys.argv[1]
if not os.path.isfile(model):
print("Error: Not a valid model.")
sys.exit(-1)

# capture SIGINT signal, e.g., Ctrl+C
signal.signal(signal.SIGINT, signal_handler)
# capture SIGINT signal, e.g., Ctrl+C
signal.signal(signal.SIGINT, signal_handler)

detector = snowboydecoder.HotwordDetector(model, sensitivity=0.5)
print('Listening... Press Ctrl+C to exit')
detector = snowboydecoder.HotwordDetector(model, sensitivity=0.5)
detector.detector.ApplyFrontend(False)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a new param for apply_frontend. We can now set it through initialization.

print('Listening... Press Ctrl+C to exit')

# main loop
detector.start(detected_callback=snowboydecoder.play_audio_file,
interrupt_check=interrupt_callback,
sleep_time=0.03)
# main loop
detector.start(detected_callback=snowboydecoder.play_audio_file,
interrupt_check=interrupt_callback,
sleep_time=0.03)

detector.terminate()
detector.terminate()

if __name__ == "__main__":
main()
1 change: 0 additions & 1 deletion examples/Python3/requirements.txt

This file was deleted.

1 change: 0 additions & 1 deletion examples/Python3/snowboydetect.py

This file was deleted.

8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@


py_dir = 'Python' if sys.version_info[0] < 3 else 'Python3'
swig_dir = os.path.join('swig', py_dir)

class SnowboyBuild(build):

def run(self):

cmd = ['make']
swig_dir = os.path.join('swig', py_dir)
def compile():
call(cmd, cwd=swig_dir)

Expand All @@ -39,14 +39,14 @@ def compile():

setup(
name='snowboy',
version='1.3.0',
version='1.3.1',
description='Snowboy is a customizable hotword detection engine',
maintainer='KITT.AI',
maintainer_email='[email protected]',
license='Apache-2.0',
url='https://snowboy.kitt.ai',
packages=find_packages(os.path.join('examples', py_dir)),
package_dir={'snowboy': os.path.join('examples', py_dir)},
packages=find_packages(swig_dir),
package_dir={'snowboy': swig_dir},
py_modules=['snowboy.snowboydecoder', 'snowboy.snowboydetect'],
package_data={'snowboy': ['resources/*']},
zip_safe=False,
Expand Down
2 changes: 1 addition & 1 deletion swig/Python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ else
CXX := g++
PYINC := $(shell python-config --cflags)
PYLIBS := $(shell python-config --ldflags)
SWIGFLAGS := -shared
SWIGFLAGS := -Wl,-O1,--as-needed -shared
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the -O1 option here asks the compiler to do level 1 optimizations, might be helpful

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont understand. What do you mean? Was this just a "hey, thats good!" or are you requesting some change? I am already using -O1?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh OK sorry, mis-read it... I thought "SWIGFLAGS := -Wl,-O1,--as-needed -shared" was the original line.

CXXFLAGS += -std=c++0x
# Make sure you have Atlas installed. You can statically link Atlas if you
# would like to be able to move the library to a machine without Atlas.
Expand Down
4 changes: 2 additions & 2 deletions swig/Python3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ else
CXX := g++
PYINC := $(shell python3-config --cflags)
PYLIBS := $(shell python3-config --ldflags)
SWIGFLAGS := -shared
SWIGFLAGS := -Wl,-O1,--as-needed -shared
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, the -O1 option here asks the compiler to do level 1 optimizations, might be helpful

CXXFLAGS += -std=c++0x
# Make sure you have Atlas installed. You can statically link Atlas if you
# would like to be able to move the library to a machine without Atlas.
ifneq ("$(ldconfig -p | grep lapack_atlas)","")
LDLIBS := -lm -ldl -lf77blas -lcblas -llapack_atlas -latlas
else
LDLIBS := -lm -ldl -lf77blas -lcblas -llapack -latlas
LDLIBS := -lm -lcblas
endif
SNOWBOYDETECTLIBFILE = $(TOPDIR)/lib/ubuntu64/libsnowboy-detect.a
ifneq (,$(findstring arm,$(shell uname -m)))
Expand Down
File renamed without changes.
File renamed without changes.