码农之家
卫薇
给大家带来的一篇关于树莓派相关的电子书资源,介绍了关于树莓派、开发、实战方面的内容,本书是由人民邮电出版社出版,格式为PDF,资源大小64.4 MB,蒙克编写,目前豆瓣、亚马逊、当当、京东等电子书综合评分为:8.8,更多相关的学习资源可以参阅 程序设计电子书、等栏目。
树莓派(Raspberry Pi)是这款应用场景Linux系统软件的、只能一張透支卡尺寸的卡片式电子计算机。产品研发树莓派的最初目地是根据廉价硬件配置和自由软件来促进大学的基本电子计算机课程文化教育,但迅速树莓派就获得电子计算机和硬件配置发烧友的亲睐;她们用它学编程,并造就出各式各样奇特的、红极一时的硬件软件运用。
这书由多产作家Simon Monk撰写,是将內容开展全方位升級以后的第2版,包揽了丰富多彩的实践实例,详尽解读了树莓派的配备与管理方法、数据连接、电脑操作系统及手机软件。另一个,这书还详细介绍了应用PHP开展树莓派开发设计的各类方法,书中详细介绍了相关PHP程序编写的基本知识、目录与词典、PHP高級特点。一起,这书还详细介绍了相关机器视觉、硬件基础、操纵硬件配置、电动机、大数字键入、控制器、显示系统、物联网技术及Arduino等有关专业知识。
这书合适程序猿和电子计算机软、硬件配置发烧友,及其对树莓派很感兴趣的小读者阅读文章,也合适做为树莓派有关实践课程内容的具体指导用书。
基于树莓派的语音对话机器人
本文实例为大家分享了基于树莓派的语音对话机器人,供大家参考,具体内容如下
第一部分代码
arecord -D "plughw:1" -f S16_LE -r 16000 -d 3 /home/pi/Desktop/voice.wav
第二部分代码
# coding: utf-8 import sys import json import urllib2 import base64 import requests reload(sys) sys.setdefaultencoding(“utf-8”) def get_access_token(): url = “https://openapi.baidu.com/oauth/2.0/token” body = { “grant_type”:”client_credentials”, “client_id” :”此处填写自己的client_id”, “client_secret”:”此处填写自己的client_secret”, } r = requests.post(url,data=body,verify=True) respond = json.loads(r.text) return respond["access_token"] def yuyinshibie_api(audio_data,token): speech_data = base64.b64encode(audio_data).decode(“utf-8”) speech_length = len(audio_data) post_data = { “format” : “wav”, “rate” : 16000, “channel” : 1, “cuid” : “B8-27-EB-BA-24-14”, “token” : token, “speech” : speech_data, “len” : speech_length } url = "http://vop.baidu.com/server_api" json_data = json.dumps(post_data).encode("utf-8") json_length = len(json_data) #print(json_data) req = urllib2.Request(url, data=json_data) req.add_header("Content-Type", "application/json") req.add_header("Content-Length", json_length) #print("asr start request\n") resp = urllib2.urlopen(req) #print("asr finish request\n") resp = resp.read() resp_data = json.loads(resp.decode("utf-8")) if resp_data["err_no"] == 0: return resp_data["result"] else: print(resp_data) return None def asr_main(filename,tok): try: f = open(filename, “rb”) audio_data = f.read() f.close() resp = yuyinshibie_api(audio_data,tok) return resp[0] except Exception,e: print “e:”,e return “识别失败”.encode(“utf-8”)
第三部分代码
# coding: utf-8 import requests import json import sys reload(sys) sys.setdefaultencoding("utf-8") def Tuling(words): Tuling_API_KEY = "此处填写自己的Turling KEY" body = {"key":Tuling_API_KEY,"info":words.encode("utf-8")} url = "http://www.tuling123.com/openapi/api" r = requests.post(url,data=body,verify=True) if r: date = json.loads(r.text) print date["text"] return date["text"] else: return None
第四部分代码
# coding: utf-8 import sys import urllib2 import json import os import yuyinshibie reload(sys) sys.setdefaultencoding("utf-8") def yuyinhecheng_api(tok,tex): cuid = "B8-27-EB-BA-24-14" spd = "4" url = "http://tsn.baidu.com/text2audio?tex="+tex+"&lan=zh&cuid="+cuid+"&ctp=1&tok="+tok+"&per=3" #print url #response = requests.get(url) #date = response.read() return url def tts_main(filename,words,tok): voice_date = yuyinhecheng_api(tok,words) f = open(filename,"wb") f.write(voice_date) f.close()
第五部分代码
# coding: utf-8 import os import time import yuyinhecheng import Turling import yuyinshibie tok = yuyinshibie.get_access_token() switch = True while switch: os.system('sudo arecord -D "plughw:1" -f S16_LE -r 16000 -d 3 /home/pi/Desktop/voice.wav') time.sleep(0.5) info = yuyinshibie.asr_main("/home/pi/Desktop/voice.wav",tok) if '关闭'.encode("utf-8") in info: while True: os.system('sudo arecord -D "plughw:1" -f S16_LE -r 16000 -d 10 /home/pi/Desktop/voice.wav') time.sleep(10) info = yuyinshibie.asr_main("/home/pi/Desktop/voice.wav",tok) if '开启'.encode("utf-8") in info: break url = "http://tsn.baidu.com/text2audio?tex=开启成功&lan=zh&cuid=B8-27-EB-BA-24-14&ctp=1&tok="+tok+"&per=3" os.system('mpg123 "%s"'%url) elif '暂停'.encode("utf-8") in info: url = "http://tsn.baidu.com/text2audio?tex=开始暂停&lan=zh&cuid=B8-27-EB-BA-24-14&ctp=1&tok="+tok+"&per=3" os.system('mpg123 "%s"'%url) time.sleep(10) url = "http://tsn.baidu.com/text2audio?tex=暂停结束&lan=zh&cuid=B8-27-EB-BA-24-14&ctp=1&tok="+tok+"&per=3" os.system('mpg123 "%s"'%url) continue else: tex = Turling.Tuling(info) url = yuyinhecheng.yuyinhecheng_api(tok,tex) os.system('mpg123 "%s"'%url) time.sleep(0.5)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持码农之家。
上一篇:Bootstrap与jQuery UI框架设计 下一篇:Node.js调试指南
展开 +
收起 -
驱动树莓派gpio的中间层库函数有wiringPi,BCM2835,以及PRi.GPIO,这里我选择使用Python语言开发的PRi.GPIO。 1、安装RPi.GPIO (1)先安装python-dev,输入以下指令。 sudo apt-get install python-dev (2)安装RPi.GPIO wget https://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.5.11.tar.gz#解压:tar -zxvf RPi.GPIO-0.5.11.tar.gz#进入解压之后的目录 :cd RPi.GPIO-0.5.3a#启动安装 :sudo python setup.py install 2、编写驱动电机的程序 (1)树莓派与XY-160D驱动板连接方法 # 树莓派供电:# 5V电源正极接到树莓派4号5V电源引脚,负极接到树莓派39号GND引脚# 树莓派绿色ATC灯闪烁则SD卡正在运行,红色PWR灯常亮则供电正常# 更多指示灯状态请参照:树莓派LED指示灯状态的解释## 驱动板电源端供电:# 14.8V电源接驱动板电源端正极,电源负极接驱动板电源端负极## 驱动板信号端供电:# 树莓派1号引脚3.3V接到驱动板信号端+5V引脚,14号引脚GND接到驱动板信号端GND引脚# 驱动板供电正常则DS1指示灯亮起 (2)代码 使用一段简单的电机驱动代码进行测试,新建motor_drive.py文件,添加如下代码并保存: #!/usr/bin/python2#coding=utf-8import RPi.GPIO as GPIOimport time # 初始化设置引脚输出IN1 = 12 #11号引脚对应GPIO0,12号引脚对应GPIO1IN2 = 11 #11号与12号引脚分别接到驱动板IN2,IN1引脚,控制其中一侧电机IN3 = 13 #13号引脚对……
本文实例为大家分享了树莓派使用USB摄像头和motion实现监控的具体代码,供大家参考,具体内容如下 一、工具 1、树莓派3B 2、USB摄像头 二、操作步骤 1、安装motion sudo apt-get install motion 2、配置motion (1) sudo nano /etc/default/motion 将里面的no修改成yes,让motion可以一直在后台运行: start_motion_daemon=yes (2) sudo nano /etc/motion/motion.conf 修改配置文件,这个文件比较长,请确保一下参数的配置。在nano编辑器下,可以使用^w快速查找到如下配置内容。也可以使用^v向下翻页。 3、启动motion sudo motion 4、查看视频数据 在局域网内的设备,不管是手机还是电脑,均可打开浏览器访问 树莓派IP:8081 5、退出motion killall -TERM motion 或者 service motion stop 三、可能出现的问题 1、配置错误 出现Unknown config option "sdl_threadnr" 解决方法: 在配置文件中,直接将这一行内容进行注释。不是下图光标所在处,是光标下面sdl_threadnr 0这一行,注释成# sdl_threadnr 0即可。 2、8081页面无法显示 在8081端口,无法显示数据,但是在8080端口可以看到motion的信息。 解决方法: 这可能是摄像头没有被识别,可以将摄像头拔下重新插入。 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持码农之家。 ……
两个树莓派,在同一个局域网内,传输文件,采用socket方式。 client端代码: import socketimport osimport hashlibclient = socket.socket() # 生成socket,连接serverip_port =("192.168.137.210",12346) # server地址和端口号(最好是10000以后)client.connect(ip_port) # 连接print("服务器已连接")while True: content = input("")if len(content)==0: continue # 如果传入空字符会阻塞if content.startswith("get"): client.send(content.encode("utf-8")) # 传送和接收都是bytes类型 # 1.先接收长度,建议8192server_response = client.recv(1024)file_size = int(server_response.decode("utf-8")) print("接收到的大小:",file_size)# 2.接收文件内容client.send("准备好接收".encode("utf-8")) # 确认接收filename = "new" + content.split(" ")[1]f = open(filename, "wb") received_size = 0m = hashlib.md5() while received_size file_size: size = 0 # 准确接收数据大小,解决粘包 if file_size - received_size 1024: # 多次接收 size = 1024 else: # 最后一次接收完毕 size = file_size - received_size data = client.recv(size) # 多次接收内容,接收大数据 data_len = len(data) received_size += data_len print("已接收:", int(received_size/file_size*100), "%") m.update(data) f.write(data) f.close() print("实际接收的大小:", received_size) # 解码# 3.md5值校验md5_sever = client.recv(1024).decode("utf-8") md5_client = m.hexdigest() print("服务器发来的md5:",md5_sever) print("接收文件的……
Copyright 2018-2020 xz577.com 码农之家
电子书资源由网友、会员提供上传,本站记录提供者的基本信息及资源来路
鸣谢: “ 码小辫 ” 公众号提供回调API服务、“ 脚本CDN ”提供网站加速(本站寻求更多赞助支持)
版权投诉 / 书籍推广 / 赞助:520161757@qq.com
上传资源(网友、会员均可提供)
基于树莓派的语音对话机器人
本文实例为大家分享了基于树莓派的语音对话机器人,供大家参考,具体内容如下 第一部分 代码 arecord -D "plughw:1" -f S16_LE -r 16000 -d 3 /home/pi/Desktop/voice.wav 第二部分 代码 # coding: utf-8import sys import json import urllib2 import base64 import requestsreload(sys) sys.setdefaultencoding(“utf-8”)def get_access_token(): url = “https://openapi.baidu.com/oauth/2.0/token” body = { “grant_type”:”client_credentials”, “client_id” :”此处填写自己的client_id”, “client_secret”:”此处填写自己的client_secret”, }r = requests.post(url,data=body,verify=True)respond = json.loads(r.text)return respond["access_token"]def yuyinshibie_api(audio_data,token): speech_data = base64.b64encode(audio_data).decode(“utf-8”) speech_length = len(audio_data) post_data = { “format” : “wav”, “rate” : 16000, “channel” : 1, “cuid” : “B8-27-EB-BA-24-14”, “token” : token, “speech” : speech_data, “len” : speech_length }url = "http://vop.baidu.com/server_api"json_data = json.dumps(post_data).encode("utf-8")json_length = len(json_data)#print(json_data) req = urllib2.Request(url, data=json_data)req.add_header("Content-Type", "application/json")req.add_header("Content-Length", json_length) #print("asr start request\n")resp = urllib2.urlopen(req)#print("asr finish request\n")resp = resp.read()resp_data = json.loads(resp.decode("utf-8"))if resp_data["err_no"] == 0: return resp_data["resul……