-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from nyumaya/experimental_mac_support
Experimental mac support
- Loading branch information
Showing
7 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Test basic functionality on multiple platforms | ||
|
||
on: | ||
push: | ||
branches: ['master', 'V3.1'] | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-13] | ||
node-version: [12.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install_Deps | ||
run: | | ||
if [ "${{ matrix.os }}" == "macos-13" ]; then | ||
brew install portaudio | ||
pip install pydub | ||
pip install pyaudio | ||
else | ||
pip install pydub | ||
fi | ||
- name: Test | ||
run: cd python/test ; python3 verify_marvin.py |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import time | ||
import os | ||
import argparse | ||
import sys | ||
import datetime | ||
|
||
sys.path.append('../../python/src') | ||
|
||
from libnyumaya import AudioRecognition, FeatureExtractor | ||
from auto_platform import default_libpath | ||
|
||
from pydub import AudioSegment | ||
|
||
def split_sequence(a,seg_length): | ||
return [a[x:x+seg_length] for x in range(0,len(a),seg_length)] | ||
|
||
|
||
def load_audio_file(filename): | ||
sound = None | ||
sound = AudioSegment.from_wav(filename) | ||
sound = sound.set_frame_rate(16000) | ||
sound = sound.set_channels(1) | ||
sound = sound.set_sample_width(2) | ||
duration = sound.duration_seconds | ||
|
||
return sound,duration | ||
|
||
def detectKeywords(libpath,wavpath): | ||
wav,dur = load_audio_file(wavpath) | ||
extractor = FeatureExtractor(libpath) | ||
detector = AudioRecognition(libpath) | ||
extactor_gain = 1.0 | ||
|
||
keywordId = detector.addModel('../../models/Hotword/marvin_v3.1.286.premium',0.5) | ||
bufsize = detector.getInputDataSize()*2 | ||
|
||
wav = wav.get_array_of_samples().tobytes() | ||
splitdata = split_sequence(wav,bufsize) | ||
|
||
for i,frame in enumerate(splitdata): | ||
if(bufsize == len(frame)): | ||
features = extractor.signalToMel(frame) | ||
prediction = detector.runDetection(features) | ||
if(prediction > 0): | ||
return 1 # Keyword detected | ||
|
||
return 0 # No keyword detected | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser() | ||
|
||
parser.add_argument( | ||
'--libpath', type=str, | ||
default=default_libpath, | ||
help='Path to Platform specific nyumaya_lib.') | ||
|
||
FLAGS, unparsed = parser.parse_known_args() | ||
res_pos = None | ||
res_neg = None | ||
try: | ||
res_pos = detectKeywords(FLAGS.libpath, "./nearfield_marvin.wav") # Positive Example | ||
res_neg = detectKeywords(FLAGS.libpath, "./nearfield_sheila.wav") # Negative Example | ||
except: | ||
print("Test crashed") | ||
sys.exit(1) | ||
|
||
if( res_pos == 1 and res_neg == 0): | ||
print("Test result OK") | ||
sys.exit(0) | ||
else: | ||
print("Test result FAILED") | ||
sys.exit(1) | ||
|
||
|