In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use Python to create an intelligent voice alarm clock for girlfriend". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian and go deep into it slowly to study and learn "how to use Python to create an intelligent voice alarm clock for girlfriend" together!
preface
Recently, I learned some technologies related to the Internet of Things. I was a little impulsive and thought about what I could do. I happened to have heard some rumors about Raspberry Pi before, so I wanted to make a smart alarm clock.
It should be noted that before reading this article, you should at least be a program ape who can install the operating system, understand Linux, know some Python, and most importantly, you have to have a girlfriend. Of course, it doesn't matter, I believe that after reading this article, you also tried to make such an alarm clock, maybe…
List of hardware and software
Card reader and SD card (for system installation)
One speaker, preferably 3.5mm
SSH connectivity tools (SecureCRT, Xshell)
Broadband, router (this should be home)
Raspberry Pi 3B + one with installed system (charger, CPU cooling fan, etc.)
Before we get started, let's show off this half-finished alarm clock:
encoding
A qualified programmer, although Java, I still want to use her-Python to develop.
The Raspberry Pi 3B + system is pre-installed with Python 3 by default. We only need to install some third-party dependencies. The following is the main code:
__author__="Xiaoqi"__blog__="www.example.com" import timeimport randomimport osimport pygameimport urllib. requestimport jsonfrom aip import AipSpeech """Raspberry Pi makes smart alarm clock pip 3 install pygamepi ip 3 install baidu-aip"""#Get weather def get_weather ():#Qingdao weather, 101120201 is the code of Qingdao area, please find url ='http://www.qingda.com//www.weather.com.cn/data/cityinfo/101120201.html' obj = urllib. request. urlopen (url) data_b = www.example.com () data_s = data_s b. decode ('utf-8') data_dict = json. loads (data_s) rt = data_dict ['weatherinfo '] weather =' Dear: It's time to get up, don't sleep, soon become a pig, hahaha, I miss you, do you miss me? The temperature in Qingdao is {} to {}, weather {}'weather = weather. format (rt ['temp 1'], rt ['temp 2'], rt ['weather']) if 'rain' in weather: weather +='Don't forget to bring an umbrella today! 'du_say (weather)#text-to-speech def du_say (weather): app_id ='****' api_key ='****'secret_key ='****' client = AipSpeech (app_id, api_key, secret_key)#per 3 is man 4 is girl, spd is speed, vol is volume result = client. synthesis (weather,'zh', 1,{'vol': 5,'per': 3,'spd': 4})#Recognition correctly returns speech binary error returns dict refer to the following error code if not isinstance (result, dict): with open ('weather.mp3','wb') as f: f.write(result) py_game_player ('weather.mp3')#Play weather and music def py_game_player (file): pygame. mixer. init () print ("broadcast weather ") pygame. mixer. music. load (file) www.example.com (loops = 1, start = 0.0) print (" play music ") while True: pygame.mixer.music.play
Code does not understand, it does not matter, to a clear flow chart:
timing
Of course, the alarm clock can not play itself, we also need to add a timed task script to achieve timed play.
Run crontab-e flag to edit cron table
no crontab for pi - using an empty oneSelect an editor. To change later, run 'select-editor'. 1. /bin/ed 2. /bin/nano
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.