from IPython.display import Image, display display(Image('light_bulb.png', height=100)) while True: print('Turn your light: ') ans = input() if ans in ['on','off','red','blue','green','pink','orange','yellow','cyan','purple']: display(Image('https://portal.iclass.hk/school_resources/img/light_bulb_'+ans+'.png', height=100)) else: break print()cloudvision.py import cloudspeech, time, display, cloudvision display.showImage("light_bulb_red.png") while True: print("Say ...") if t==None: continue t = t.lower() if ...: break
# pip install googletrans==4.0.0rc1 # https://python.plainenglish.io/build-a-simple-language-translation-program-using-python-60b22b492a94 # https://py-googletrans.readthedocs.io/en/latest/ from googletrans import * tr = Translator() x = tr.translate("Ich liebe dich",dest='zh-cn') print(x.text) y = tr.translate("안녕하세요",dest='zh-tw') print(y.text) z = tr.translate("你好嗎,明天會更好",dest="ko") print(z.text)
!pip install googletrans==4.0.0-rc1 # https://py-googletrans.readthedocs.io/en/latest/ dest language list # https://zhuanlan.zhihu.com/p/411621178 from googletrans import Translator tr = Translator() t = tr.translate("Good morning", dest="zh-CN") print(t.text)
!pip install gtts from gtts import gTTS from IPython.display import Audio tts = gTTS('你好嗎', lang="zh") tts = gTTS('你好嗎', lang="yue") tts = gTTS('감사합니다', lang="ko") sound_file = 'output.mp3' tts.save(sound_file) Audio(sound_file, autoplay=True)
# pip install pillow from PIL import Image img = Image.open("sheep.png") img.show()![]()
tts.say("Hello, how are you? Nice to meet you!", pitch=-5, speaking_rate=0.5) 音高 -20 to 20 pitch 速度 0.25 to 4 speaking_rate (=1) tts.say("你好嗎", lang="yue-HK") tts.say("你好嗎", lang="cmn-CN") tts.say("괜찮으세요", lang="ko-KR") tts.say("죄송합니다", lang="ko-KR") tts.say("감사합니다", lang="ko-KR")
#pip install pyttsx3 import pyttsx3 import os engine = pyttsx3.init() engine.setProperty('rate', 200) voice = engine.getProperty('voices') engine.setProperty('voice', voice[1].id) print(engine.getProperty('voice')) engine.setProperty('volume', 0.5) txt = "Hello Python London bridge is falling down. 兩岸猿聲啼不住,輕舟已過萬重山。"; engine.say(txt) engine.runAndWait() engine.setProperty('voice', voice[3].id) fn = "test.mp3" engine.save_to_file(txt, fn) engine.runAndWait() os.system("start "+fn)