Skip to content

Commit

Permalink
Merge pull request #39 from nyumaya/experimental_mac_support
Browse files Browse the repository at this point in the history
Experimental mac support
  • Loading branch information
yodakohl authored Apr 7, 2024
2 parents 9f723e7 + 33f03f5 commit b985f29
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 1 deletion.
29 changes: 29 additions & 0 deletions .github/workflows/test-multi-platform.yml
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 added lib/mac/arm64/libnyumaya_premium.3.1.0.dylib
Binary file not shown.
Binary file added lib/mac/x86_64/libnyumaya_premium.3.1.0.dylib
Binary file not shown.
2 changes: 1 addition & 1 deletion python/src/auto_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
if system == "Darwin":
from cross_record import AudiostreamSource
play_command ="play -q"
default_libpath = '../lib/mac/libnyumaya.dylib'
default_libpath = '../../lib/mac/x86_64/libnyumaya_premium.3.1.0.dylib'

elif system == "Linux":
from record import AudiostreamSource
Expand Down
Binary file added python/test/nearfield_marvin.wav
Binary file not shown.
Binary file added python/test/nearfield_sheila.wav
Binary file not shown.
75 changes: 75 additions & 0 deletions python/test/verify_marvin.py
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)


0 comments on commit b985f29

Please sign in to comment.