Esempio n. 1
0
    def main(self, tok):

        bt = baidu_tts()
        bs = baidu_stt(1, 2, 3, 4)
        r = recorder()
        e = email()

        mail_host = 'smtp.qq.com'  #这里默认qq邮箱,可以更改
        mail_user = ''  #邮箱账户
        mail_pass = ''  #邮箱密码
        mail_port = '465'  #与邮箱服务商相通
        sender = '*****@*****.**'
        receivers = []

        bt.tts('欢迎使用小蓝邮件助手,请问您有什么需要吗', tok)
        speaker.speak()
        speaker.ding()
        r.record()
        speaker.dong()
        commands = bs.stt('./voice.wav', tok)
        command = e.command_choose(commands, tok)
        if command == 'send':
            e.send(mail_host, mail_user, mail_pass, mail_port, sender, tok)
        else:
            bt.tts('对不起,我们还暂时不支持该功能', tok)
            speaker.speak()
Esempio n. 2
0
def start(text, token):

    """
    启动
    :param text: 文本
    :param token: token
    :return:
    """
    r = recorder()
    bt = baidu_tts()
    bs = baidu_stt(1, 'a', 2, '{')
    song_list = ["冲鸭冲鸭.mp3", "招财进宝.mp3", "毒液前来.mp3", "跟着我一起.mp3"]
    ycy = "杨超越,1998年7月31日出生于江苏省盐城市,中国内地流行乐女歌手,女子演唱组合CH2、火箭少女101成员。 2017年,加入女子演唱组合CH2,从而正式出道,并签约了多家游戏平台,为高校电竞比赛做内容推广;同年,随CH2相继推出了《启航》、《听雪恋歌》等单曲。2018年,参加腾讯视频女团青春成长节目《创造101》,最终获得第3名,并加入女子演唱组合火箭少女101;8月18日,随火箭少女101推出组合首张EP专辑《撞》;9月23日,推出首支个人单曲《跟着我一起》;11月15日,推出第2支个人单曲《冲鸭冲鸭》;11月27日,推出第3支个人单曲《招财进宝》;12月15日,获得“影响中国”年度人物荣誉盛典年度演艺人物奖。2019年,她被评选为LikeTCCAsia亚太区最美100张面孔第3位、中国区最美100张面孔第1位呢!"
    bt.tts(ycy, token)
    speaker.speak()
    bt.tts("我这里还有杨超越姐姐唱的歌哦~要不要听一听呢?", token)
    speaker.speak()
    speaker.ding()
    r.record()
    speaker.dong()
    text = bs.stt("./voice.wav", token)
    if "不" in text:
        bt.tts("哦,那好吧~再见啦", token)
        speaker.speak()
    else:
        bt.tts("那你想要听什么呢?不知道的话,可以说随机哦~", token)
        speaker.speak()
        speaker.ding()
        r.record()
        speaker.dong()
        text = bs.stt("./voice.wav", token)
        if "随机" in text:
            speaker.play(song_list[random.randint(0, 4)])
        else:
            kugou_request(text)
Esempio n. 3
0
def convenstation():

    b = baidu_stt(1, 3, 2, '{')
    r = recorder()
    s = skills()
    speaker.ding()
    r.record()
    speaker.dong()
    tok = b.get_token()
    text = b.stt('./voice.wav', tok)
    intent = nlu.get_intent(text)
    s.getskills(intent, text, tok)
Esempio n. 4
0
    def start(self, tok):  #判断

        bt = baidu_tts()
        bs = baidu_stt(1, 2, 3, 4)
        r = recorder()
        h = hass()
        welcome = '欢迎使用小蓝专用智能家居控制系统!请在,滴,一声之后说出指令'

        bt.tts(welcome, tok)
        speaker.speak()
        speaker.ding()
        r.record()
        speaker.dong()
        text = bs.stt('./voice.wav', tok)

        while text == None:
            sorry = '对不起,我没有听清楚,请重复一遍'
            bt.tts(sorry, tok)
            speaker.speak()
            speaker.ding()
            r.record()
            speaker.speak()
            text = bs.stt('./voice.wav', tok)
            if text != None:
                break
        texts = str.encode(encoding='UTF-8', errors='strict')
        if '打开' in text:
            cortolthings = texts[6:-2]
            cortolmode = 'turn_on'
            h.cortol(cortolthings, cortolmode, tok)
        elif '关闭' in text:
            cortolthings = texts[6:-2]
            cortolmode = 'turn_off'
            h.cortol(cortolthings, cortolmode, tok)
        elif '查看' in text:
            if '传感器' in text:
                getstatethings = texts[6:-5]
                getmode = 'sensor'
                h.sensor(getstatethings, tok)
        if '红外' in text:
            if '学习' in text:
                h.study(tok)

        else:
            h.usuallycortol(text, tok)
Esempio n. 5
0
    def send(self, mail_host, mail_user, mail_pass, mail_port, sender, tok):

        bt = baidu_tts()
        bs = baidu_stt(1, 2, 3, 4)
        r = recorder()
        e = email()
        receivers = []

        bt.tts('请问您要给谁发送邮件呢?格式为,邮箱数字加邮箱服务商,如,一五二六七八九,QQ邮箱', tok)
        speaker.speak()
        speaker.ding()
        r.tsrecord()
        speaker.dong()
        receivers[0] = bs.stt('./voice.wav', tok)
        bt.tts('请问您要发送什么内容?', tok)
        speaker.speak()
        speaker.ding()
        r.tsrecord()
        speaker.dong()
        messages = bs.stt('./voice.wav', tok)

        message = MIMEText(messages, 'plain', 'utf-8')
        message['From'] = Header("小蓝邮件代发", 'utf-8')
        message['To'] = Header("You", 'utf-8')
        subject = '小蓝邮件代发'
        message['Subject'] = Header(subject, 'utf-8')

        try:
            smtpObj = smtplib.SMTP()
            smtpObj.connect(mail_host, mail_port)
            smtpObj.login(mail_user, mail_pass)
            smtpObj.sendmail(sender, receivers, message.as_string())
            bt.tts('邮件发送成功', tok)
            speaker.speak()
        except smtplib.SMTPException:
            bt.tts('无法发送邮件', tok)
            speaker.speak()
Esempio n. 6
0
def main(tok):

    r = recorder()
    bt = baidu_tts()
    url = 'https://snowboy.kitt.ai/api/v1/train/'
    apikey = '78ee816d9bfc8fb0e01341d4408e3f23fbbc9b03'
    askf = '第一次训练录音开始,请在滴一声之后说出,blueberry'
    asks = '第二次训练录音开始,请在滴一声之后说出,blueberry'
    askt = '第三次训练录音开始,请在滴一声之后说出,blueberry'
    bt.tts(askf, tok)
    speaker.speak()
    speaker.ding()
    r.train_f_record()
    speaker.dong()
    bt.tts(asks, tok)
    speaker.speak()
    speaker.ding()
    r.train_s_record()
    speaker.dong()
    bt.tts(askt, tok)
    speaker.speak()
    speaker.ding()
    r.train_t_record()
    speaker.dong()
    wav1 = "/home/pi/old_xiaolan/old_xiaolan/train_f.wav"
    wav2 = "/home/pi/old_xiaolan/old_xiaolan/train_s.wav"
    wav3 = "/home/pi/old_xiaolan/old_xiaolan/train_t.wav"
    out = "/home/pi/old_xiaolan/old_xiaolan/snowboy/blueberry.pmdl"
    data = {
        "name":
        hotword_name,
        "language":
        language,
        "age_group":
        age_group,
        "gender":
        gender,
        "microphone":
        microphone,
        "token":
        token,
        "voice_samples": [{
            "wave": get_wave(wav1)
        }, {
            "wave": get_wave(wav2)
        }, {
            "wave": get_wave(wav3)
        }]
    }

    response = requests.post(endpoint, json=data)
    if response.ok:
        with open(out, "w") as outfile:
            outfile.write(response.content)
        print "Saved model to '%s'." % out
        trueback = "Saved model to '%s'." % out
        bt.tts(tureback, tok)
        speaker.speak()
    else:
        print "Request failed."
        print response.text
Esempio n. 7
0
    def cortol(self, cortolthings, cortolmode, tok):  #智能家居中的灯、开关控制于此(支持一句话插件)

        bt = baidu_tts()
        bs = baidu_stt(1, 2, 3, 4)
        r = recorder()
        h = hass()
        url = 'http://hassio.local'
        port = '8123'
        passwd = 'y20050801'
        headers = {'x-ha-access': passwd, 'content-type': 'application/json'}

        domains = h.service()
        e_id = h.e_id()
        cortolthings = unicode(cortolthings, "utf-8", "ignore")

        try:
            if cortolmode == 'turn_on':
                if e_id[cortolthings] != None:
                    if 'switch' in e_id[cortolthings]:
                        color_name = 'a'
                        service = '/api/services/switch/turn_on'
                    elif 'light' in e_id[cortolthings]:
                        ask = '请问要设置什么颜色,可以忽略'
                        bt.tts(ask, tok)
                        speaker.speak()
                        speaker.ding()
                        r.record()
                        speaker.dong()
                        color_name_f = bs.stt('./voice.wav', tok)
                        if color_name_f != None:
                            color_name = h.chosecolor(color_name_f)
                        else:
                            color_name = 'a'
                        service = '/api/services/light/turn_on'
                    elif 'automation' in e_id[cortolthings]:
                        color_name = 'a'
                        service = '/api/services/automation/turn_on'
            elif cortolmode == 'turn_off':
                if e_id[cortolthings] != None:
                    if 'switch' in e_id[cortolthings]:
                        color_name = 'a'
                        service = '/api/services/switch/turn_off'
                    elif 'light' in e_id[cortolthings]:
                        color_name = 'a'
                        service = '/api/services/light/turn_off'
                    elif 'automation' in e_id[cortolthings]:
                        color_name = 'a'
                        service = '/api/services/automation/turn_off'
        except KeyError:
            sorry = '对不起,控制设备不存在,请注意!控制设备的名称得跟在homeassistant上设置的friendly,name一样'
            bt.tts(sorry, tok)
            speaker.speak()
        except TypeError:
            sorry = '对不起,控制设备不存在,请注意!控制设备的名称得跟在homeassistant上设置的friendly,name一样'
            bt.tts(sorry, tok)
            speaker.speak()
        except ValueError:
            sorry = '对不起,控制设备不存在,请注意!控制设备的名称得跟在homeassistant上设置的friendly,name一样'
            bt.tts(sorry, tok)
            speaker.speak()
        else:
            pass

        try:

            cortole_id = e_id[cortolthings]
            if color_name == 'a':
                dataf = {"entity_id": cortole_id.encode('utf-8')}
                data = json.dumps(dataf)
            else:
                dataf = {
                    "color_name": color_name,
                    "entity_id": cortole_id.encode('utf-8')
                }
                data = json.dumps(dataf)
        except KeyError:
            sorry = '对不起,控制设备不存在,请注意!控制设备的名称得跟在homeassistant上设置的friendly,name一样'
            bt.tts(sorry, tok)
            speaker.speak()
        except TypeError:
            sorry = '对不起,控制设备不存在,请注意!控制设备的名称得跟在homeassistant上设置的friendly,name一样'
            bt.tts(sorry, tok)
            speaker.speak()
        except ValueError:
            sorry = '对不起,控制设备不存在,请注意!控制设备的名称得跟在homeassistant上设置的friendly,name一样'
            bt.tts(sorry, tok)
            speaker.speak()
        else:
            print data
            cortolback = requests.post(url + ':' + port + service,
                                       headers=headers,
                                       data=data)
            if cortolback.status_code == 200 or cortolback.status_code == 201:
                sayback = '执行成功'
                bt.tts(sayback, tok)
                speaker.speak()
            else:
                sayback = '执行错误'
                bt.tts(sayback, tok)
                speaker.speak()
Esempio n. 8
0
def main(tok):
    APPKEY = 'b8fff66168feb233d5cdb2f7931750f3'
    url = 'http://v.juhe.cn/toutiao/index?type='
    r = recorder()
    bt = baidu_tts()
    bs = baidu_stt(1, 'a', 2, '{')
    newsserviceasktext = '请问您要听什么新闻?'

    bt.tts(newsserviceasktext, tok)
    speaker.speak()
    speaker.ding()
    r.record()
    speaker.dong()
    text = bs.stt('./voice.wav', tok)
    chose = random.randint(0, 9)

    if '国内新闻' in text:
        newsservice = 'chinanews'
    elif '国际新闻' in text:
        newsservice = 'nationnews'
    elif '科技新闻' in text:
        newsservice = 'kejinews'
    elif '体育新闻' in text:
        newsservice = 'tiyunews'
    else:
        newsservice = 't'

    if newsservice == 'chinanews':
        newstype = 'guonei'
        r = requests.post(url + newstype + '&key=' + APPKEY)
        json = r.json()
        if chose == 0:
            saytext = json['result']['data'][0]['title']
        elif chose == 1:
            saytext = json['result']['data'][1]['title']
        elif chose == 2:
            saytext = json['result']['data'][2]['title']
        elif chose == 3:
            saytext = json['result']['data'][3]['title']
        elif chose == 4:
            saytext = json['result']['data'][4]['title']
        elif chose == 5:
            saytext = json['result']['data'][5]['title']
        elif chose == 6:
            saytext = json['result']['data'][6]['title']
        elif chose == 7:
            saytext = json['result']['data'][7]['title']
        elif chose == 8:
            saytext = json['result']['data'][8]['title']
        elif chose == 9:
            saytext = json['result']['data'][9]['title']
        else:
            saytext = json['result']['data'][0]['title']
        bt.tts(saytext, tok)
        speaker.speak()

    elif newsservice == 'nationnews':
        newstype = 'guoji'
        r = requests.post(url + newstype + '&key=' + APPKEY)
        json = r.json()
        if chose == 0:
            saytext = json['result']['data'][0]['title']
        elif chose == 1:
            saytext = json['result']['data'][1]['title']
        elif chose == 2:
            saytext = json['result']['data'][2]['title']
        elif chose == 3:
            saytext = json['result']['data'][3]['title']
        elif chose == 4:
            saytext = json['result']['data'][4]['title']
        elif chose == 5:
            saytext = json['result']['data'][5]['title']
        elif chose == 6:
            saytext = json['result']['data'][6]['title']
        elif chose == 7:
            saytext = json['result']['data'][7]['title']
        elif chose == 8:
            saytext = json['result']['data'][8]['title']
        elif chose == 9:
            saytext = json['result']['data'][9]['title']
        else:
            saytext = json['result']['data'][0]['title']
        bt.tts(saytext, tok)
        speaker.speak()

    elif newsservice == 'kejinews':
        newstype = 'keji'
        r = requests.post(url + newstype + '&key=' + APPKEY)
        json = r.json()
        if chose == 0:
            saytext = json['result']['data'][0]['title']
        elif chose == 1:
            saytext = json['result']['data'][1]['title']
        elif chose == 2:
            saytext = json['result']['data'][2]['title']
        elif chose == 3:
            saytext = json['result']['data'][3]['title']
        elif chose == 4:
            saytext = json['result']['data'][4]['title']
        elif chose == 5:
            saytext = json['result']['data'][5]['title']
        elif chose == 6:
            saytext = json['result']['data'][6]['title']
        elif chose == 7:
            saytext = json['result']['data'][7]['title']
        elif chose == 8:
            saytext = json['result']['data'][8]['title']
        elif chose == 9:
            saytext = json['result']['data'][9]['title']
        else:
            saytext = json['result']['data'][0]['title']
    elif newsservice == 'tiyunews':
        newstype = 'tiyu'
        r = requests.post(url + newstype + '&key=' + APPKEY)
        json = r.json()
        if chose == 0:
            saytext = json['result']['data'][0]['title']
        elif chose == 1:
            saytext = json['result']['data'][1]['title']
        elif chose == 2:
            saytext = json['result']['data'][2]['title']
        elif chose == 3:
            saytext = json['result']['data'][3]['title']
        elif chose == 4:
            saytext = json['result']['data'][4]['title']
        elif chose == 5:
            saytext = json['result']['data'][5]['title']
        elif chose == 6:
            saytext = json['result']['data'][6]['title']
        elif chose == 7:
            saytext = json['result']['data'][7]['title']
        elif chose == 8:
            saytext = json['result']['data'][8]['title']
        elif chose == 9:
            saytext = json['result']['data'][9]['title']
        else:
            saytext = json['result']['data'][0]['title']
    else:
        newstype = 'top'
        r = requests.post(url + newstype + '&key=' + APPKEY)
        json = r.json()
        if chose == 0:
            saytext = json['result'][0]['title']
        elif chose == 1:
            saytext = json['result'][1]['title']
        elif chose == 2:
            saytext = json['result'][2]['title']
        elif chose == 3:
            saytext = json['result'][3]['title']
        elif chose == 4:
            saytext = json['result'][4]['title']
        elif chose == 5:
            saytext = json['result'][5]['title']
        elif chose == 6:
            saytext = json['result'][6]['title']
        elif chose == 7:
            saytext = json['result'][7]['title']
        elif chose == 8:
            saytext = json['result'][8]['title']
        elif chose == 9:
            saytext = json['result'][9]['title']
        else:
            saytext = json['result'][0]['title']
        bt.tts(saytext, tok)
        speaker.speak()