Skip to content

Commit

Permalink
Added support for Python3
Browse files Browse the repository at this point in the history
  • Loading branch information
chenguoguo committed Aug 3, 2016
1 parent b8f5416 commit 3262b6d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions examples/Python/snowboydecoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def extend(self, data):

def get(self):
"""Retrieves data from the beginning of buffer and clears it"""
tmp = ''.join(self._buf)
tmp = bytes(bytearray(self._buf))
self._buf.clear()
return tmp

Expand Down Expand Up @@ -88,7 +88,7 @@ def audio_callback(in_data, frame_count, time_info, status):
model_str = ",".join(decoder_model)

self.detector = snowboydetect.SnowboyDetect(
resource_filename=resource, model_str=model_str)
resource_filename=resource.encode(), model_str=model_str.encode())
self.detector.SetAudioGain(audio_gain)
self.num_hotwords = self.detector.NumHotwords()

Expand All @@ -100,7 +100,7 @@ def audio_callback(in_data, frame_count, time_info, status):
"(%d) does not match" % (self.num_hotwords, len(sensitivity))
sensitivity_str = ",".join([str(t) for t in sensitivity])
if len(sensitivity) != 0:
self.detector.SetSensitivity(sensitivity_str);
self.detector.SetSensitivity(sensitivity_str.encode())

self.ring_buffer = RingBuffer(
self.detector.NumChannels() * self.detector.SampleRate() * 5)
Expand Down
3 changes: 1 addition & 2 deletions swig/Android/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
# When you extract Android toolchain from Android NDK, make sure you supply
# --stl=libc++ option. This Makefile is optimized for armv7-a architecture.

# Some versions of swig does not work well. We prefer compiling swig from source
# code. We have tested swig-3.0.7.tar.gz.
# Please use swig-3.0.10 or up.
SWIG := swig

# Please specify your NDK root directory here.
Expand Down
7 changes: 3 additions & 4 deletions swig/Python/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Example Makefile that converts snowboy c++ library (snowboy-detect.a) to
# python library (_snowboydetect.so, snowboydetect.py), using swig.

# Some versions of swig does not work well. We prefer compiling swig from source
# code. We have tested swig-3.0.7.tar.gz.
# Please use swig-3.0.10 or up.
SWIG := swig

SNOWBOYDETECTSWIGITF = snowboy-detect-swig.i
Expand All @@ -16,8 +15,8 @@ LDFLAGS :=

ifeq ($(shell uname), Darwin)
CXX := clang++
PYINC := $(shell /usr/bin/python2.7-config --includes)
PYLIBS := $(shell /usr/bin/python2.7-config --ldflags)
PYINC := $(shell python-config --includes)
PYLIBS := $(shell python-config --ldflags)
SWIGFLAGS := -bundle -flat_namespace -undefined suppress
LDLIBS := -lm -ldl -framework Accelerate
SNOWBOYDETECTLIBFILE = $(TOPDIR)/lib/osx/libsnowboy-detect.a
Expand Down
4 changes: 4 additions & 0 deletions swig/Python/snowboy-detect-swig.i
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
%}

%include "include/snowboy-detect.h"

%begin %{
#define SWIG_PYTHON_STRICT_BYTE_CHAR
%}

0 comments on commit 3262b6d

Please sign in to comment.