Adhearsion初体验
原文地址:http://blog.tech4k.com/?p=282
我是偶尔在Asterisk: The Future of Telephony
上看到Adhearsion
的介绍的.以下是摘自Adhearsion
主页http://adhearsion.com/
的一段对Adhearsion
的定义.
简单的说就是基于Asterisk
AGI,一套完整的应用于Voice Application的Ruby
框架.VoIP
Application + Ruby
,还有什么比这个更适合我呢?二话不说,马上开始试用.
Adhearsion Getting Start
Adhearsion
的主页还是非常的人性化的。不仅提供了完全免费,电话测试系统,使得你建立的Adhearsion
应用可以方便的进行调试运行,还提供了多种Voice客户端的选择,包括Skype, 各种SIP
Phones甚至In-browser Phone。按照下面的步骤,你可以轻松的建立你的第一个Adhearsion
Application.
Step 1:注册
Adhearsion
帐号
默认会加入Adhearsion
的Mailing List,不算很热闹,偶尔会有一些邮件。Adhearsion
帐号同时也是电话系统的测试帐号,有了它你就可以连接到Adhearsion
提供的SandBox上了.
Step 2:安装Ruby
, RubyGems,
Adhearsion
Ruby
和Gems的安装就不多说了.安装Adhearsion
也就是一句话的事情.感谢伟大的Ubuntu和RubyGems.
sudo gem install adhearsion
Step 3:创建你的第一个
Adhearsion
应用
类似Rails,Adhearsion
会创建一整套基础部件,解决了类似Adhearsion
服务器启动,停止等工作,使得你可以专心在Adhearsion
应用的开发上.
ahn create my_first_app
Step 4:启用Sandbox Component
Adhearsion
中有一个Component的概念.Component类似插件的意思,代表了一组功能的集合.所有的Components都放在my_first_app/components目录下.其中Sandbox就是一个包含了连接注册Adhearsion
电话测试系统的Component.
cd my_first_app ahn enable component sandbox
修改my_first_app/components/sandbox/sandbox.yml,按照你在Ahearsion注册的帐号密码修改该文件,这样你无需编写任何代码就可以连接注册到Adhearsion
电话测试系统了.
username: xxxxxxx password: xxxxxxx
Step 5:编写你的
Adhearsion
应用
打开my_first_app/dialplan.rb,添加如下代码:
sandbox {
play "hello-world"
}
sandbox
代表的是Asterisk
中规定的context,Adhearsion
测试系统默认的context就是sandbox. play “hello-world”
的意思就是播放”hello-world”的音频.简单的就好像说话一样-.-
Step 6:运行你的
Adhearsion
应用
直接通过ahn命令就可以运行你的Adhearsion
应用了.由于启用了sandbox component,你的应用会先去连接Adhearsion
测试系统进行登录注册,然后启动后台进程监听请求.
ahn start .
OK了,这就是Adhearsion
全部需要做得了.测试一下吧.选一款你觉得最酷的soft phone,按照Ahdearsion的提示拨打电话,听到一声清脆的”Hello World”,你的Adhearsion
蹦出一些log信息.看这就爽,你也快来试试看吧.
上一篇: 22. 括号生成