Mar 14 2008

Converting WAV file to GSM file

Category: PHPBipin Balakrishnan @ 3:21 pm

soundvisualizer.png

Want to convert a sound file of type wav to gsm in your web application.You can use the code below.There are may desktop application softwares such as

switch,audacity which converts the sound format.Suppose we need in a web application in which we uploads the wav file and and it got converted into a gsm or any other format(depends on our need).

For me i need the wav file in gsm format as the output for some IVR application.

Before writing the code we need a opensource software called sox

to be installed in our system.Sox is a sound converter which converts sound from any format to any other sound format.

The rest is simple

copy and paste the code below

Uploading interface: HTML

Give some file name with extension Html or PHP

<form enctype=”multipart/form-data” action=”uploader.php” method=”POST”>
<input type=”hidden” name=”MAX_FILE_SIZE” value=”10000000″ />
Choose a file to upload: <input name=”uploadedfile” type=”file” /><br />
<input type=”submit” value=”Upload File” />
</form>

Conversion program :

<?php
$target_path = “uploads/”;
$file_name=basename( $_FILES['uploadedfile']['name']);
$new = substr($file_name,0,-3).”gsm”;
$cmd = “sox “.$file_name.” -r 8000 -c1 “.$new.” resample -ql”;
exec($cmd);
rename(“$new”, “uploads/$new”);
?>


Mar 13 2008

Build your own PBX in your office

Category: AsteriskBipin Balakrishnan @ 7:01 pm

We  can build a telephone exchange in our office without any cost.An exchange that we can make calls internally to phone( both soft phone and IP phones) with out having any cost.All we need is a lan connection.Got shocked!!!.

Nothing to wonder it can be make possible by “open source asterisk telephony platform” .I am not going to explain all about the asterisk but a simple introduction and how to set a small PBX in our office.

Asterisk is an open source telephony platform which can able to do all the thing that traditional EPABX can do or much more than it also supports VoIP. Or in other words we can tell it a Software PBX.

For creating a simple PBX to make calls between the soft phones we needs to asterisk installed in the system.Any Linux OS can be used for the installation.You can download asterisk from the official asterisk site www.asterisk.org

commands:

tar xvfz asteris-*

cd asterisk-*

./configure

make

make install

ok now asterisk is installed in your system.

For starting asterisk issue command:

asterisk -vvvvgc

you will get a conslole like this

screenshot-asterisk-console-on-bipin-laptop-pid-8044.png

Our Exchange is ready now.

Install soft phones in your friends machine .

Lots of free soft phone are available to download one such you can get form here

Ok ..now your telephones are ok .Now ne need is to assign numbers to the soft phones and set the the domain as the asterisk server IP address

Soft phone will be some thing simliar to this.

3.JPG

Assign number say for example.200, and 100 for two soft phone in two computers connected to the LAN which includes the asterisk server.

Edit files in the asterisk servers.

First edit sip.conf

location: /etc/asterisk/sip.conf

add these configuration

[200]
port = 5060
type=friend
context=switch
username=200
secret=200
callerid=200
host=dynamic
canreinvite=yes
disallow=all
allow=all

[100]
port = 5060
type=friend
context=switch
username=100
secret=100
callerid=200
host=dynamic
canreinvite=yes
disallow=all
allow=all

edit extension.conf

location: /etc/asterisk/extension.conf

copy paste this at end of the file

[switch]
exten => 200,1,Dial(SIP/200)
exten => 100,1,Dial(SIP/100)

Restart asterisk by giving “reload” command in the console which we get when we start asterisk.
Now your phone will get registered.Start calling from your soft phone installed in your PC to your friend.

More to learn visit asterisk.org, voipinfo


Mar 05 2008

MYSQL query in Dialplan

Category: AsteriskBipin Balakrishnan @ 7:41 pm

It is necessary in many application with the dialplan that we need to qurey from the database and pass the result to the aserisk dialplan command.Previously we had to use to use AGI (Asterisk Gateway Interface) for accomplish this task.This is we need some programming part to be done.Non programmers don’t worry now an application called MYSQL() is avilable with asterisk 1.4 and above.We can use this application as normal asterisk application and can give the MSQL qurey inside it. For this to work we have to install asterisk-addon first.

syntax :

MYSQL(Connect connid dhhost dbuser dbpass dbname)

Connects to a database. Arguments contain standard MySQL parameters passed to function mysql_real_connect. Connection identifer returned in ${connid}. If the connection wasn’t possible, then ${connid} == “”.

MYSQL(Query resultid ${connid} query-string)

Executes standard MySQL query contained in query-string using established connection identified by ${connid}. Result of query is stored in ${resultid}.

MYSQL(Fetch fetchid ${resultid} var1\ var2\ …\ varN)

If any rows are available to select, ${fetchid} is set to 1 and a single row is fetched from a result set contained in ${resultid}. The return fields are assigned to ${var1}, ${var2} … ${varN} respectively. If no rows are left to select, ${fetchid} is set to 0 and ${var1}, ${var2} … ${varN} remain unchanged.

MYSQL(Clear ${resultid})

Frees memory and data structures associated with result set.

MYSQL(Disconnect ${connid})

Disconnects from named connection to MySQL.

Example

[mysqlcal]
 exten => 555,1,Answer
 exten => 555,n,MYSQL(Connect connid localhost bipin bipin voice_alerts)
 exten => 555,n,NoOp(${cnum})
 exten => 555,n,NoOp(${jid})
 exten => 555,n,MYSQL(Query resultid ${connid} INSERT INTO `callerinfo` (`number`) VALUES ('${CALLERID(num)}'))
 exten => 555,n,MYSQL(Query resultid ${connid} UPDATE `callerinfo` SET `status` = \'ANSWERED\' WHERE `job`=${jid} AND `number`=${cnum})

Tags: , ,