activate: use a right audio player for mac osx

Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
pull/14/head
Wu Zhangjin 2018-06-07 22:16:48 +08:00 committed by Matthew D. Scholefield
parent 031a72061e
commit b14c4b34b8
4 changed files with 17 additions and 7 deletions

View File

@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from random import randint
from subprocess import Popen
from threading import Event
from prettyparse import create_parser
@ -21,6 +20,7 @@ from prettyparse import create_parser
from precise.pocketsphinx.listener import PocketsphinxListener
from precise_runner import PreciseRunner
from precise_runner.runner import ListenerEngine
from precise.util import play_audio
usage = '''
Run Pocketsphinx on microphone audio input
@ -48,7 +48,7 @@ def main():
args = create_parser(usage).parse_args()
def on_activation():
Popen(['aplay', '-q', 'data/activate.wav'])
play_audio('data/activate.wav')
def on_prediction(conf):
print('!' if conf > 0.5 else '.', end='', flush=True)

View File

@ -14,14 +14,13 @@
# limitations under the License.
from os.path import join
from random import randint
from subprocess import Popen
from threading import Event
import numpy as np
from prettyparse import create_parser
from precise.network_runner import Listener
from precise.util import save_audio, buffer_to_audio
from precise.util import save_audio, buffer_to_audio, play_audio
from precise_runner import PreciseRunner
from precise_runner.runner import ListenerEngine
@ -51,7 +50,8 @@ def main():
args = create_parser(usage).parse_args()
def on_activation():
Popen(['aplay', '-q', 'data/activate.wav'])
play_audio('data/activate.wav')
if args.save_dir:
global chunk_num
nm = join(args.save_dir, args.save_prefix + session_id + '.' + str(chunk_num) + '.wav')

View File

@ -55,6 +55,16 @@ def save_audio(filename: str, audio: np.ndarray):
save_audio = (audio * np.iinfo(np.int16).max).astype(np.int16)
wavio.write(filename, save_audio, pr.sample_rate, sampwidth=pr.sample_depth, scale='none')
def play_audio(filename: str):
"""
Args:
filename: Audio filename
"""
import platform
from subprocess import Popen
player = 'play' if platform.system() == 'Darwin' else 'aplay'
Popen([player, '-q', filename])
def glob_all(folder: str, filt: str) -> List[str]:
"""Recursive glob"""

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from argparse import ArgumentParser
from subprocess import Popen
from precise.util import play_audio
from precise_runner import PreciseRunner, PreciseEngine
from threading import Event
@ -28,7 +28,7 @@ def main():
print('!' if prob > 0.5 else '.', end='', flush=True)
def on_activation():
Popen(['aplay', '-q', 'data/activate.wav'])
play_audio('data/activate.wav')
engine = PreciseEngine(args.engine, args.model)
PreciseRunner(engine, on_prediction=on_prediction, on_activation=on_activation,