ubuntu 十分钟后提醒我 ###背景
非常受用windows phone上cortana的语音指令: 十分钟分钟后叫我起床。 一小时后提醒我做XXX。
###思路
ubuntu下语音识别很难搞,只好搞了个命令行的东西来做几分钟后提醒我这样的事情。
几分钟后干什么,用程序实现起来很容易。golang的time.after_func就可以。 然后就是响铃,没弄明白beep命令是怎么用的,倒是又发现了espeak命令。
espeak是一个文字转语音的程序,俗称TTS。
sudo apt-get install espeak
espeak "it's time to get up"
###golang代码如下:
package main
import (
"flag"
"os/exec"
"time"
)
var n_secs int
var n_mins int
var n_hours int
var words string
func init() {
flag.IntVar(&n_secs, "s", 0, "remind me after n seonds")
flag.IntVar(&n_mins, "m", 0, "remind me after n minutes")
flag.IntVar(&n_hours, "h", 0, "remind me after n hours")
flag.StringVar(&words, "w", "ling ling ling", "the words to speak when time is up")
}
func main() {
var c = make(chan int)
var d time.Duration = 0
flag.Parse()
switch {
case n_secs != 0:
d += time.Duration(n_secs) * time.Second
case n_mins != 0:
d += time.Duration(n_mins) * time.Minute
case n_hours != 0:
d += time.Duration(n_hours) * time.Hour
}
time.AfterFunc(d, func() {
exec.Command("espeak", words).Run()
c <- 1
})
<-c
}
###用法:
remindme -m 5
remindme -m 30 -w "homework homework"
remindme -h 1 -m 30 -w "clean the room, clean the room"