Пример #1
0
def main():
    # 创建录音设备(平台相关)
    audio = Audio()
    # 创建唤醒引擎
    wakeup_engine = WakeupEngine()
    # 创建播放器(平台相关)
    player = Player()
    # 创建duerOS核心处理模块
    dueros = DuerOS(player)
    dueros.set_directive_listener(directive_listener)

    
    model = cnfg.getConfigValue("snowboy","snowboyPmdl")
    snowboyName = cnfg.getConfigValue("snowboy","snowboyName")
    # SnowBoy唤醒引擎实体
    snowboy = SnowBoy(model)

    audio.link(wakeup_engine)
    wakeup_engine.link(dueros)
    wakeup_engine.set_wakeup_detector(snowboy)

    prompt_tone_player = PromptTone(player)

    def wakeup():
        '''
        唤醒回调
        :return:
        '''
        print snowboyName+'已唤醒,我能为你做些什么?'
        # 唤醒态提示音
        prompt_tone_player.play()
        dueros.listen()

    snowboy.set_callback(wakeup)

    dueros.start()
    wakeup_engine.start()
    snowboy.start()
    audio.start()

    print '请说'+snowboyName+'来唤醒我。'

    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            break

    dueros.stop()
    wakeup_engine.stop()
    audio.stop()
    snowboy.stop()
Пример #2
0
import sys
import os
import time
import raspberrypi
import datetime
import pygame
from aip.aip import AipSpeech
if sys.getdefaultencoding() != 'utf-8':
    reload(sys)
    sys.setdefaultencoding('utf-8')

from app.framework import player
playObj = player.Player()

from cnf import config as cnfg
APP_ID = cnfg.getConfigValue("user", "app_id")
API_KEY = cnfg.getConfigValue("user", "client_id")
SECRET_KEY = cnfg.getConfigValue("user", "client_secret")
aipSpeech = AipSpeech(APP_ID, API_KEY, SECRET_KEY)


#file:///tmp/205472.mp3
class Modular:
    def getDuerOSRet(self, string):
        string = string.replace("u'", "'")  # 这里比较简单,实际中需要用正则条件替换
        string = string.replace("'", '"')
        textDict = json.loads(string)
        ret = textDict['payload']['text']
        # ret = ret.decode('unicode-escape')
        self.strCompare(ret)
        return ret
Пример #3
0
from sdk.dueros_core import DuerOS
from app.framework.player import Player
from app.framework.mic import Audio
from app.snowboy import snowboydecoder
from app.utils.prompt_tone import PromptTone

logging.basicConfig(level=logging.INFO)

############## HuangDayu add ############
from mod import modular as mod
modObj=mod.Modular()
import cnf.config as cnfg
#########################################


sensitivityVolue = cnfg.getConfigValue("snowboy","sensitivityVolue")


class SnowBoy(object):
    '''
    基于SnowBoy的唤醒类
    '''

    def __init__(self, model):
        '''
        SnowBoy初始化
        :param model:唤醒词训练模型
        '''
        self.calback = None
        self.detector = snowboydecoder.HotwordDetector(model, sensitivity=sensitivityVolue, audio_gain=1)
Пример #4
0
# -*- coding: utf-8 -*-
'''
OAuth2.0认证
'''
import sdk.auth as auth

import cnf.config as cnfg

# 开发者注册信息
CLIENT_ID = cnfg.getConfigValue("user", "client_id")
CLIENT_SECRET = cnfg.getConfigValue("user", "client_secret")


def main():
    # 使用开发者注册信息
    auth.auth_request(CLIENT_ID, CLIENT_SECRET)

    # 使用默认的CLIENT_ID和CLIENT_SECRET
    #auth.auth_request()


if __name__ == '__main__':
    main()