Пример #1
0
def translate(input,language_to):
    translate = Translator()

    if language_to in lan:
        
        #say = '你好嗎'
        result = translate.translate(input ,dest=lan.get(language_to))
        #result = translate.translate(say ,dest=lan.get('日文'))
        #result = translate.translate('我想吃晚餐',dest=lan.get('日文'))

        #speak(result.text,lan.get(l))
        TTS(result.text,language_to)
        #print (result.text)
        return result.text
    else:
        
        TTS('我不懂','中文')
Пример #2
0
def weather_forecast(date,city):
    if city in woeid:
        #處理dialogflow的Timestamp
        json_to_date = dateutil.parser.parse(date, ignoretz=True).strftime("%d %b %Y")
        print(json_to_date)

        #load weather's json file
        res = requests.get('https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D' + woeid.get(city) + '%20and%20u%3D%22c%22&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys')# + woeid.get(city))
        data = json.loads(res.text)
        forecast = data['query']['results']['channel']['item']['forecast']

        #print results
        for i in range(len(forecast)) :
            if json_to_date == forecast[i]['date']:
                print('氣溫:' + forecast[i]['high'] + '°C~' + forecast[i]['low'] + '°C 天氣狀況:' + forecast[i]['text'])
                TTS('氣溫:' + forecast[i]['high'] + '°C~' + forecast[i]['low'] + '°C 天氣狀況:' + forecast[i]['text'],'中文')
    else:
        TTS('我不懂','中文')
Пример #3
0
def weather_current(city):
    if city in woeid:
        #load weather's json file
        res = requests.get('https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D' + woeid.get(city) + '%20and%20u%3D%22c%22&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys')
        data = json.loads(res.text)

        data = data['query']['results']['channel']

        atmosphere = data['atmosphere']
        humidity = atmosphere['humidity']

        item = data['item']
        temp = item['condition']['temp']
        #print results
        print('溫度:' + temp + '°C' + ' 濕度:' + humidity + '% 天氣狀況:' + item['condition']['text'])
        TTS('溫度:' + temp + '°C' + ' 濕度:' + humidity + '% 天氣狀況:' + item['condition']['text'],'中文')
    else:
        TTS('我不懂','中文')
Пример #4
0
def translate(l):
    translate = Translator()

    if l == '':
        TTS('要翻譯成什麼語言', '中文')
        l = speech('要翻譯成什麼語言', 2, 2)

    TTS('我正在聽', '中文')
    say = speech('我正在聽', 2, 2)
    #say = '你好嗎'
    result = translate.translate(say, dest=lan.get(l))
    #result = translate.translate(say ,dest=lan.get('日文'))
    #result = translate.translate('我想吃晚餐',dest=lan.get('日文'))

    #speak(result.text,lan.get(l))
    TTS(result.text, l)
    #print (result.text)
    return result.text
Пример #5
0
def get_unread():
    try:
        unread_msgs = GMAIL.users().messages().list(
            userId='me', labelIds=[label_id_one, label_id_two]).execute()
        mssg_list = unread_msgs['messages']
        print("未讀信件數: ", str(len(mssg_list)))
        unread_msgs_sum = "你有" + str(len(mssg_list)) + "封未讀信件"
        TTS(unread_msgs_sum, '中文')
    except (KeyError):
        print("沒有新信件")
        pass
Пример #6
0
def all_news(last):
    #ticks=time.time()
    #print(ticks)
    for i in range(0, 3):
        #print(top_headlines['articles'][i]['title'])
        #print(top_headlines['articles'][i]['description'])
        if last['articles'][i]['description'] == None:
            news = last['articles'][i]['title'] + '。\n'
        else:
            news = last['articles'][i]['title'] + '。\n' + last['articles'][i][
                'description'] + '。\n'
        #print(news)
        TTS(news, '中文')

    #ticks2=time.time()
    #print(ticks2-ticks)
    return news
Пример #7
0
def speech(title, duration, i):
    r = sr.Recognizer()
    with sr.Microphone() as source:
        r.adjust_for_ambient_noise(source, duration)
        print(title)
        #speak(title,'zh-tw')
        TTS(title, '中文')
        time.sleep(i)
        audio = r.listen(source)
        try:
            recognize = r.recognize_google(audio, language="zh-TW")
            print(recognize)
        except sr.UnknownValueError:
            recognize = "無法辨識!"
        except sr.UnboundLocalError:
            recognize = "無法辨識!"
    return recognize
Пример #8
0
def speech(title, duration):
    r = sr.Recognizer()
    with sr.Microphone() as source:
        r.adjust_for_ambient_noise(source, duration)
        print(title)
        TTS(title, '中文')
        audio = r.listen(source)
        try:
            recognize = r.recognize_bing(
                audio,
                key="ca9c8dea98a74ef0bf98b5519a5010f3",
                language="zh-TW")
            print(recognize)
        except sr.UnknownValueError:
            recognize = "無法辨識!"
        except sr.UnboundLocalError:
            recognize = "無法辨識!"
    return recognize
Пример #9
0
def read_gmail():
    try:
        unread_msgs = GMAIL.users().messages().list(
            userId='me', labelIds=[label_id_one, label_id_two]).execute()
        mssg_list = unread_msgs['messages']
        for mssg in mssg_list:
            temp_dict = {}
            m_id = mssg['id']
            message = GMAIL.users().messages().get(userId=user_id,
                                                   id=m_id).execute()
            payld = message['payload']
            headr = payld['headers']
            for one in headr:
                if one['name'] == 'Date':
                    msg_date = one['value']
                    date_parse = (parser.parse(msg_date))
                    m_date = (date_parse.date())
                    temp_dict['日期'] = str(m_date)
                    print('日期: ' + temp_dict['日期'])
                else:
                    pass

            for two in headr:
                if two['name'] == 'From':
                    msg_from = two['value']
                    temp_dict['發送人'] = msg_from
                    print('發送人: ' + temp_dict['發送人'])

            for three in headr:
                if three['name'] == 'Subject':
                    msg_subject = three['value']
                    temp_dict['主旨'] = msg_subject
                    print('主旨: ' + temp_dict['主旨'])
                else:
                    pass

            temp_dict['信件預覽'] = message['snippet']
            TTS(
                '日期' + temp_dict['日期'] + '發送人' + temp_dict['發送人'] + '主旨' +
                temp_dict['主旨'], '中文')
            GMAIL.users().messages().modify(userId=user_id,
                                            id=m_id,
                                            body={
                                                'removeLabelIds': ['UNREAD']
                                            }).execute()
            #read = speech("是否繼續閱讀?",5)
            #if read == '是':
            #print (temp_dict['信件預覽'])
            #TTS('信件預覽'+temp_dict['信件預覽'],'中文')
            #elif read == '否':
            #pass

            #ans = speech("是否要標示為已讀?",5)
            '''if ans == '是':
				GMAIL.users().messages().modify(userId=user_id, id=m_id,body={ 'removeLabelIds': ['UNREAD']}).execute()'''
            #elif ans == '否':
            #pass
            #important = speech("是否標示為重要訊息?",5)
            #if important == '是':
            #GMAIL.users().messages().modify(userId=user_id, id=m_id,body={ 'removeLabelIds': [], 'addLabelIds': ['STARRED']}).execute()
            #elif important != '是':
            #pass
    except (KeyError):
        TTS('沒有未讀信件', '中文')
        pass
Пример #10
0
from BingTTS import TTS

#TTS(sentence,la) la=中文/英文/日文
TTS('你好嗎', '中文')