我的香橙派闹钟-v0.1 mini

项目描述

想要做一个闹钟,然后一步一步完善。 毕竟想做很久了,所以总归算是填坑吧

手头的香橙派装的Ubuntu18.04 应该是

记录下来主要怕这老爷车零部件每一步都是临时凑出来的之后哪个部件想不起来就G了

目前的定时方案

使用的是crontab做的定时方案使用的命令是

复制代码
crontab -e

被#注释的东西不必在意,目前只做了一个任务

当时的参考文章,后期找到了高级用法,有空看看 ,感觉能用到

bash 复制代码
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
50 7 * * 1-5 python /home/orangepi/code/alarm/play.py
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

显然,命令的意思是周一到周五每天早上执行python play. 比如这周要变成周一到周六,那么1-5改成1-6。真是个悲伤的故事。。。。

python 播放音乐

我的python文件路径是"/home/orangepi/code/alarm/play.py",mp3或者说音频文件存放的路径是"/home/orangepi/code/alarm/mp3"

overpath是用百度paddle生成的一段早安音频

python 复制代码
import time
import pygame
import os
from mutagen.mp3 import MP3

# def play_music(filep) :
list1=os.listdir(r"/home/orangepi/code/alarm/mp3")
list2 = []
for i in list1:
    s=os.path.join(r"/home/orangepi/code/alarm/mp3",i)
    list2.append(s)

morningPath = os.path.join(r"/home/orangepi/code/voice", r"morning.wav")
overPath = os.path.join(r"/home/orangepi/code/voice", r"over.wav")
# 初始化
pygame.mixer.init()
# 加载音乐
pygame.mixer.music.load(overPath)
# 音量设置
pygame.mixer.music.set_volume(80)
# 播放音乐
pygame.mixer.music.play()
# 播放时间
time.sleep(10)

for n in list2:
    # 获取每一首歌的时长
    audio = MP3(n)
    pygame.mixer.init()
    path = n
    pygame.mixer.music.load(path)
    pygame.mixer.music.play()
    time.sleep(int(audio.info.length))

# 关闭音乐

pygame.mixer.music.stop()

早安音频生成

overpath是用百度paddle生成的一段早安音频,

既然用了,这里就挂个广告吧,不过我在香橙派上部署的cpu的,等以后装个主机挂个GPU,在服务器上跑应该会更好。目前只能说,,,能用。且免费。

shell 复制代码
git clone https://github.com/PaddlePaddle/PaddleSpeech.git
cd PaddleSpeech
pip install pytest-runner
pip install .

安装好了之后调用语句是这样的:

bash 复制代码
paddlespeech tts --input "主人,再不起床人家会伤心的" --output over.wav

当然默认生成的是巨平淡的电子音,以后有空专门调校一下这个,看看有没有有意思的。

TBD

下一步做一个Web服务器,可以局域网往上面传音乐,局域网网页关闭音乐播放和打开音乐播放。改响铃时间。

相关推荐
OPEN-F2 分钟前
Python进阶教程:单元测试与代码质量
开发语言·python·单元测试
Logintern0923 分钟前
装饰器和洋葱模式的区分
开发语言·python·架构
工业一体机老司机25 分钟前
Linux工业一体机自启动服务配置:systemd服务单元编写与开机优化实战
java·linux·服务器
zhixingheyi_tian26 分钟前
Linux 之 ssh
linux·服务器·ssh
呆呆敲代码的小Y1 小时前
10 分钟搞懂 cua:开源 AI 操作电脑基础设施,附 Python 沙箱与 Agent 上手代码
人工智能·python·开源·ai agent·awesome·llm应用·cua
工具分享1 小时前
带店托管必用爆单AI选品,一人公司轻松掌握
人工智能·python
l1258651 小时前
# RAG低延迟架构设计:从5秒到500ms的优化全链路
数据库·人工智能·python·langchain
小鱼仙官1 小时前
Ubuntu C++ NTP校时程序
linux·c++·ubuntu
RisunJan1 小时前
Linux命令-vgdisplay(显示卷组详细属性)
linux·运维·数据库
杨丰玮4181 小时前
从零手写Java飞机躲障碍游戏|Swing绘图、鼠标跟随、计时器碰撞检测实战(五)
java·python·游戏·游戏引擎·图形渲染·动画·贴图