星期二, 9月 15, 2009

Using MD5 in C language




http://mixtt.blogspot.com/2009/06/c-using-md5-in-c-language.html





#include <openssl/md5.h>
/*Encode str to str_enc using md5 algorithm*/
void md5(char *str, char *str_enc) {
int i = 0;
unsigned char d[16];
MD5_CTX ctx;
MD5_Init(&ctx);
MD5_Update (&ctx, (char *) str, strlen(str));
MD5_Final(d, &ctx);
for (i = 0; i < 16; i++) {
sprintf(str_enc + (i*2), "%02X", d[i]);
}
str_enc[32] = 0;
}

Use C language to get MAC Address in linux





#include <stdio.h>
#include <string.h> /* for strncpy */
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>

int main(void) {
int fd;
struct ifreq ifr;

char mac[20];
fd = socket(AF_INET, SOCK_DGRAM, 0);

ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ-1);

ioctl(fd, SIOCGIFHWADDR, &ifr);

close(fd);

sprintf(mac,"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
(unsigned char)ifr.ifr_hwaddr.sa_data[0],
(unsigned char)ifr.ifr_hwaddr.sa_data[1],
(unsigned char)ifr.ifr_hwaddr.sa_data[2],
(unsigned char)ifr.ifr_hwaddr.sa_data[3],
(unsigned char)ifr.ifr_hwaddr.sa_data[4],
(unsigned char)ifr.ifr_hwaddr.sa_data[5]);

printf("eth0 mac address:%s\n", mac);

return 0;
}

星期一, 5月 11, 2009

Asterisk 整合 gtalk

gtalk.conf =>
[buddy]
username=xxx@gmail.com
disallow=all
allow=ulaw
context=google-in ;order apparently matters, needs to be placed after username= ?
connection=gtalk_account

jabber.conf =>
[gtalk_account]
type=client
serverhost=talk.google.com
username=yyy@gmail.com/Talk ;; Astersk 的 gtalk 分身,必須要有此帳號
secret=zzz ;; yyy@gmail.com 的密碼
port=5222
usetls=yes ; TLS is required by talk.google.com, you'll get a 'socket read error' without
usesasl=yes
buddy=xxx@gmail.com
buddy=aaa@gmail.com
statusmessage="From Miles Blogger"
timeout=100

;; 從 Asterisk 分機撥給 gtalk 帳號 xxx@gmail.com
;; 會從yyy@gmail.com 撥給 xxx@gmail.com

dialplan =>
exten => 888,1,NoOp(+++ Dial to xxx@gmail.com +++)
exten => 888,n,Dial(Gtalk/gtalk_account/xxx@gmail.com)
exten => 888,n,Hangup

從 xxx@gmail.com 撥給 yyy@gmail.com 會轉到 Asterisk 的 dialplan 中的
[google-in] 裡面


更多的詳情可參看:
http://www.voip-info.org/wiki/view/Asterisk+Google+Talk

星期四, 4月 30, 2009

Asterisk 整合 VoiceXML

VoiceGlue
http://www.voiceglue.org/

安裝說明
http://voiceglue.org/wiki/doku.php?id=voiceglue_0.9_installation_instructions

因為我是用Gentoo , 所以只好使用困難的安裝方法 :-)
經過一番努力安裝完成後,接著就看設定部分
http://voiceglue.org/wiki/doku.php?id=voiceglue_0.9_user_guide

測試的 Dialplan 為
exten => 6666,1,NoOp("++++ Test voiceglue +++")
exten => 6666,n,Answer
exten => 6666,n,AGI(agi://localhost/url=http%3A%2F%2Flocalhost%2Fvxml%2Fhello.vxml)
exten => 6666,n,Hangup


http://localhost/vxml/hello.vxml 內容為

(vxml version="2.0" xmlns="http://www.w3.org/2001/vxml")
(form)
(block)
(prompt)
Welcome
(/prompt)
(/block)
(/form)
(/vxml)


voiceglue 預設是使用 flite 做為 TTS,
我們可以將其改用 espeak ,使其支援中文,方法如下:
修改 voiceglue_tts_gen
將其內容改為
system ("espeak", "-s 120", "-v", "zh", "-w", $file, "\"".$ARGV[1]."\"");
system ("mv", $file, $file . ".16khz.wav");
system ("sox", $file . ".16khz.wav", "-r", "8000", $file);
system ("rm", "-f", $file . ".16khz.wav");

就是這麼簡單 :-)

試著將 http://localhost/vxml/hello.vxml
中的 Welcome 改成中文,就可以聽到中文的語音囉

PS: 網頁必須是 UTF8 格式

Asterisk & 中文 TTS

espeak
http://espeak.sourceforge.net/
有支援中文的 TTS

asterisk-espeak is a eSpeak text-to-speech module for the Asterisk open-source PBX
http://asterisk-espeak.sourceforge.net/

若是用 asterisk 1.6.x 的版本,可參考以下的說明 patch
http://www.mail-archive.com/openpkg-cvs@openpkg.org/msg21782.html


記得要在 espeak.conf 設定
voice=zh
如此才會正確的處理中文


正確 install 成功後,測試的 Dialplan 如下
exten => 900,1,NoOp("+++++ Test espeak ++++")
exten => 900,n,Answer
exten => 900,n,espeak(測試中,你好,歡迎使用 asterisk |any)
exten => 900,n,Hangup


PS: 中文必須使用 UTF8 格式