コード例 #1
0
ファイル: translate.py プロジェクト: WAETW/Project002
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
ファイル: weather.py プロジェクト: WAETW/Project002
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
ファイル: weather.py プロジェクト: WAETW/Project002
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
ファイル: speech.py プロジェクト: WAETW/Project002
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
from BingTTS import TTS

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