python123app_使用Micropython代码来实现一个GSM手机,功能包括语音和短信

Updated 22-11-17 to include Internet access. Now implements http and https GET requests via GPRS using the SIM800L HTTP AT interface - see below in section on UpyPhone Apps for example applications.

UpyPhone

Micropython code to implement a GSM mobile phone. The functionality includes voice and SMS. The hardware consists of a pyboard, an LCD160CR colour touch screen and a SIM800L module as pictured below. It is mounted on a homebrew matrix board skin which plugs into a pyboard. Below the SIM800L is a lipo charger - see below.

sim800l.jpg.........lipo_charger.jpg

The following two images show the front and rear views of the assembled phone.

front_view.jpg.........rear_view.jpg

Wiring

SIM800L pin

Pyboard pin

RXD

X1

TXD

X2

RING

X5

In addition, the button switch on the SIM800L skin is connect to ground and to pin X12 on the pyboard - pressing this button wakes up the display and sim800l.

User Interface

The following describes the User interface and functionality of UPyPhone.

Home Screen

newhomescreen.jpg

The home screen displays the current signal strength, current network that the phone is registered on and the battery charge level together with time and date (set automatically from the network). The CALL button starts a call by moving to the dial screen to enter the number. The SMS button also first changes the screen to dial and then to the write message screen once the destination number has been entered. PB changes the screen to the PhoneBook screen, Msg to the read message screen and Set to the Settings Screen. APP changes to the App screen to choose an App to execute.

Dial Screen

dialscreen.jpg.........callingscreen.jpg

After a number is input using the numeric buttons, CAL starts the call, changing screens to the calling screen as pictured. The CANCEL button hangs up the call and reverts to the home screen. The CNL button on the dial screen also reverts to the home screen without making the call. The DEL button deletes the last dialled digit.

Read Message Screen

incomingsms.jpg.........readmessage.jpg

An incoming SMS is indicated by colouring the MSG button green on the home screen as well as displaying the location that the message is stored in the sim800l module. The message is read by pressing the MSG button which retrieves the message and displays it as shown above. + and - step through the messages. D deletes the currently displayed message and Bk reverts to the home screen.

Write Message SCreen

writemessage.jpg.........writemessage1.jpg

Once a destination has been specified either by the Phone Book or by the dial screen, this screen is used to compose messages. ABC moves to capitals and 123 to numbers and symbols as shown.

Phone Book

phonebook.jpg.........incomingscreen.jpg

Phone book entries are currently declared statically in phoneui.py. A calling (or message sender) number is translated to the name of an entry if it is in the phone book. Pressing an entry in the phone book either starts a voice call or an SMS message depending on whether C (call) or M (sms) has previously been pressed - indicated by a green button background. Bk returns to the home screen.

Settings Screen

settings.jpg

Adjust screen brightness and speaker volume. The number at the bottom is pyboard free heap space which is periodically updated (with the current state of code, the maximum free heap is around 50K). CR requests the user's current free credit for pay as you go simcards - when received, this is displayed in the label above the free heap space.

Apps Screen

appscreen.jpg

Choose UpyPhone app to execute. There are currently two examples as shown below. The Currency app fetches exchange rates from http://exchangerate-api.com. The Weather app fetches current weather conditions from https://www.wunderground.com. In both cases, a user specific KEY is required to access the API. See upyapps.py.

currency.jpg.........weather.jpg

Sleep Mode

If the screen is not touched for 30 seconds then the phone goes into sleep mode. In sleep mode, the pyboard is put into the "sleeping" state, the display is turned off and the sim800l module is put into "slow clock" mode. Power consumption drops from around 80ma to less than 5ma. The phone is woken up by an incoming call, sms or by pressing the wake up button.

好的,下面是一个简单的Python代码实现百度语音识别API的过程: 1. 安装Python SDK 首先需要安装百度语音识别API的Python SDK,可以使用以下命令: ``` pip install baidu-aip ``` 2. 导入SDK 在Python代码使用以下代码导入SDK: ```python from aip import AipSpeech ``` 3. 设置API信息 在代码中设置API的相关信息,包括App ID、API Key和Secret Key: ```python APP_ID = 'Your App ID' API_KEY = 'Your API Key' SECRET_KEY = 'Your Secret Key' client = AipSpeech(APP_ID, API_KEY, SECRET_KEY) ``` 4. 读取语音文件 使用Python的`wave`库读取语音文件,可以使用以下代码: ```python import wave with wave.open('audio.wav', 'rb') as f: audio_data = f.readframes(f.getnframes()) ``` 这里的`'audio.wav'`是语音文件的路径,需要根据实际情况进行修改。 5. 调用API进行识别 使用以上设置的`client`对象调用API进行语音识别,可以使用以下代码: ```python result = client.asr(audio_data, 'wav', 16000, {'dev_pid': 1536}) ``` 这里的`audio_data`是上一步读取的语音文件数据,`'wav'`表示语音文件的格式,`16000`表示采样率,`{'dev_pid': 1536}`表示使用普通话识别模型。 6. 处理识别结果 最后根据API返回的结果进行处理,可以使用以下代码: ```python if result['err_no'] == 0: print(result['result'][0]) else: print('识别失败:', result['err_msg']) ``` 这里的`result['result'][0]`表示识别结果,`result['err_no']`表示错误码,如果为0表示识别成功,否则表示识别失败。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值