Difference between revisions of "Voicemail"

From FusionPBX
Jump to: navigation, search
(This works for most of FusionPBX v2)
(Transcribing Voicemails with Nexiwave's free voicemail-to-text API)
 
(5 intermediate revisions by 2 users not shown)
Line 167: Line 167:
 
</pre>
 
</pre>
 
===Transcribing Voicemails with Nexiwave's free voicemail-to-text API===
 
===Transcribing Voicemails with Nexiwave's free voicemail-to-text API===
http://Nexiwave.com offers a free and much more accurate voicemail-to-text service. After regsiter your free account with Nexiwave, simply swap the url to wget above with something like this:
+
http://Nexiwave.com offers a free, fully automatic and much more accurate voicemail-to-text service.
 +
 
 +
====For all FusionPBX versions====
 +
After registering your free Nexiwave account, simply configure FusionPBX to use your custom Nexiwave address:
 
<pre>
 
<pre>
https://api.nexiwave.com/SpeechIndexing/file/storage/user@myemail.com/recording/?authData.passwd=XYZ&auto-redirect=true&response=application/json
+
Voicemail Mail To: joe_example.com@nexiwave.com
 
</pre>
 
</pre>
Note: you can skip the flac step, since Nexiwave accepts nearly all audio formats.
 
  
For more info, see here: http://nexiwave.com/index.php/site-map/119-integrate-in-5-minutes
+
Nexiwave will receive, transcribe and send transcribed text (and audio) to joe@example.com.
 +
 
 +
 
 +
No code change is required.
 +
 
 +
=MWI=
 +
Some phones (Cisco SPA50x series for example) will forget about MWI when they reboot.  This can be a real headache on provisioned phones.  Thankfully, there is a fix for this.
  
====This works for most of FusionPBX v2====
+
==mwi.lua==
 +
This program by default will notify all phones that have a voicemail on the system about it every 5 minutes.  You should probably enable the debug options so you can verify that it's running.
 +
 
 +
You can find the program here:
 +
/usr/local/freeswitch/scripts/app/voicemail/resources/scripts/mwi.lua
 +
 
 +
Enable Debug:
 
<pre>
 
<pre>
Code by Nexiwave
+
--debug
Index: v_mailto.php
+
        debug["sql"] = true;
===================================================================
+
        debug["info"] = true;
--- v_mailto.php (revision 1458)
 
+++ v_mailto.php (working copy)
 
 
@@ -39,6 +44,28 @@
 
ob_end_clean();
 
ob_start();
 
 
+
 
+function get_transcription($attachment_str){
 
+ // CHANGE THESE:
 
+ $username='myname@mycompany.com';
 
+ $passwd='XYZ';
 
+
 
+ $time=microtime(1);
 
+ $language="en-us";
 
+ $file_name="/tmp/vm_".$time;
 
+ file_put_contents($file_name.".wav",$attachment_str);
 
+ $result=exec("wget --max-redirect=100 -q -U 'Mozilla/5.0' --post-file $file_name.wav --header='Content-Type: audio/vnd.wav' -O - 'https://api.nexiwave.com/SpeechIndexing/file/storage/$$username/recording/?authData.passwd=$passwd&response=application/json&transcriptFormat=html&auto-redirect=true'");
 
+ unlink($file_name.".wav");
 
+
 
+ $result=json_decode($result, true);
 
+ $transcription = $result["text"];
 
+      $transcription = "Nexiwave Voicemail-to-text result: $transcription";
 
+ return $transcription;
 
+ }
 
+
 
//echo "raw message: \n".$email."\n";
 
 
//if there is a carriage return remove it and standardize on line feed
 
@@ -161,6 +188,9 @@
 
$attachment_type = "audio/wav";
 
$attachment_ext = ".wav";
 
$attachment_str = trim(substr($mimepart, strlen($subheader), strlen($mimepart)));
 
+
 
+ $transcription=get_transcription(base64_decode($attachment_str));
 
+
 
//echo "\n*** begin wav ***\n".$attachment_str."\n*** end wav ***\n";
 
break;
 
case "audio/mp3;":
 
@@ -201,8 +231,8 @@
 
$mail->From      = $v_smtpfrom;
 
$mail->FromName  = $v_smtpfromname;
 
$mail->Subject    = $var['Subject'];
 
- $mail->AltBody    = $textplain;  // optional, comment out and test
 
- $mail->MsgHTML($texthtml);
 
+ $mail->AltBody    = $textplain."\n\n$transcription";  // optional, comment out and test
 
+ $mail->MsgHTML($texthtml."<br><br>".nl2br($transcription));
 
 
 
$v_to = $var['To'];
 
 
 
 
</pre>
 
</pre>
 +
===starting===
 +
from fs_cli you can run
 +
luarun app/voicemail/resources/scripts/mwi.lua
  
====This SHOULD work for FusionPBX v3====
+
or from CLI
 +
fs_cli -x 'luarun app/voicemail/resources/scripts/mwi.lua'
 +
===auto-starting===
 +
vim /usr/local/freeswitch/conf/autoload_configs/lua.conf.xml
 +
And enable the script to auto-start
 
<pre>
 
<pre>
Index: v_mailto.php
+
    <!--
===================================================================
+
        The following options identifies a lua script that is launched
--- v_mailto.php        (revision 2811)
+
        at startup and may live forever in the background.
+++ v_mailto.php        (working copy)
+
        You can define multiple lines, one for each script you
@@ -54,6 +54,29 @@
+
        need to run.
        ob_end_clean();
+
    -->
        ob_start();
+
    <param name="startup-script" value="app/voicemail/resources/scripts/mwi.lua"/>
 +
</pre>
 +
Then restart FreeSWITCH
  
+function get_transcription($attachment_str){
+
==Notes==
+      $time=microtime(1);
+
*If the script is running you should notice the following file exists:
+      $file_name="/tmp/vm_".$time;
+
  /usr/local/freeswitch/log/mwi.tmp
+      file_put_contents($file_name.".wav",$attachment_str);
 
+      $result=exec("wget --max-redirect=100 -q -U 'Mozilla/5.0' --post-file $file_name.wav --header='Content-Type: audio/vnd.wav' -O - 'https://api.nexiwave.com/SpeechIndexing/file/storage/user@myemail.com/recording/?authData.passwd=XYZ&response=application/json&transcriptFormat=html&auto-redirect=true'");
 
+      unlink($file_name.".wav");
 
+
 
+      $result=json_decode($result, true);
 
+      $transcription = $result["text"];
 
+      $transcription = "Nexiwave Voicemail-to-text result: $transcription";
 
+      return $transcription;
 
+      }
 
+
 
+
 
+
 
  //testing show the raw email
 
        //echo "Message: \n".$msg."\n";
 
  
@@ -209,13 +232,15 @@
+
*If you enabled debug, you'll also see info like the following in your freeswitch log:
  
                                //add an attachment
+
2014-03-18 09:54:08.343349 [NOTICE] switch_cpp.cpp:1288 [voicemail] mailbox: 3161@192.168.1.4 messages: 3
                                        $mail->AddStringAttachment($parts_array["Body"],$file,$encoding,$mime_type);
+
  2014-03-18 09:54:08.343349 [NOTICE] switch_cpp.cpp:1288 [voicemail] mailbox: 3103@192.168.1.4 messages: 2
+                                        $attachments_array=$mail->GetAttachments();
+
2014-03-18 09:54:08.343349 [NOTICE] switch_cpp.cpp:1288 [voicemail] mailbox: 1342@192.168.1.4 messages: 1
+                                        $transcription=get_transcription($attachments_array[0]); //we shouldn't ever have more than one attachment
 
                        }
 
                }
 
        }
 
 
 
  //add the body to the email
 
-       $mail->AltBody    = $body_plain;  // optional, comment out and test
 
-       $mail->MsgHTML($body);
 
+      $mail->AltBody    = $body_plain."\n\n$transcription";
 
+      $mail->MsgHTML($body."<br><br>".nl2br($transcription));
 
 
 
//send the email
 
        if(!$mail->Send()) {
 
</pre>
 

Latest revision as of 15:03, 20 April 2016

Menu: (System-Voicemail)

Voicemails are listed, played, downloaded and deleted from this page.

Voicemails are shown to the FusionPBX user(s) that have been assigned to an extension. It means that the page will be populated only if the user you are logged in (ex: superadmin), has at least 1 extension assigned. FusionPBX user accounts are created in the User Manager and then are assigned on the Extensions page.

In the following example we have 2 extensions assigned to the user and extension 1001 has a voicemail.

Mailbox: 1000  	
-----------------------------------------------------------------------------------------------------------------------------
   Created    	        Caller ID Name    	   Caller ID Number    	    Folder    	    Length (play)    	Size(download) 	
Mailbox: 1001  	
-----------------------------------------------------------------------------------------------------------------------------
   Created    	        Caller ID Name    	   Caller ID Number    	    Folder    	    Length (play)    	Size(download) 	
 21 Oct 2010 3:17 am 	Extension 1000 	           1000 	            inbox 	    35 sec 	        567.29 kB
  • You can play the file by clicking over the Length ( in the example: 35 sec ).
  • You can download the file by clicking over the Size ( in the example: 567.29 kB ).

Related


Voicemail Setup

The voicemail is automatically setup for you when you install Fusionpbx, you only need to personalize it. To setup a voice mail greeting, call *98 from your extension, enter your voice mail PIN ( located in the extension setup screen) and listen to the options available. One of the options is for advanced option (#5) select this option and you will be presented with tools to record your voicemail greeting.

Multiple Email

You can add multiple email addresses in the "Voicemail Mail To:" text box. These should be comma delimited (no spaces). Example:

Voicemail Mail To: joe@example.com,joe.sixpack@example.net

Why?

Sending MMS messages to mobile phones without email plans is one reason.


Transcribing Voicemails with google speech API

It's not that great, but it's better than nothing.

You need to install sox on your system, because it only takes flac files.

apt-get install sox


And apply this patch to /secure/v_mailto.php - you must be using that to send the voicemail.

It's a little messy - it saves the WAV file again to disk, and then saves it as a flac.. might be able to do it without hitting the disk at all, but I didn't spend the time to figure it out.

Can probably do the wget also via php directly, rather than calling it, but again, I didn't figure out how.

this showed me the basics of how to do this.

This works for most of FusionPBX v2

Code by AviMarcus
Index: v_mailto.php
===================================================================
--- v_mailto.php	(revision 1458)
+++ v_mailto.php	(working copy)
 
@@ -39,6 +44,28 @@
 ob_end_clean();
 ob_start();
 
+
+function get_transcription($attachment_str){
+	$time=microtime(1);
+	$language="en-us";
+	$file_name="/tmp/vm_".$time;
+	file_put_contents($file_name.".wav",$attachment_str);
+	system("sox $file_name.wav $file_name.flac rate 16k");
+	$result=exec("wget -q -U 'Mozilla/5.0' --post-file $file_name.flac --header='Content-Type: audio/x-flac; rate=16000' -O - 'http://www.google.com/speech-api/v1/recognize?lang=$language&client=chromium'");
+	unlink($file_name.".wav");
+	unlink($file_name.".flac");
+	
+	$result=json_decode($result,1);
+	if(!is_array($result['hypotheses'])){
+		$transcription ="Free Google Speech API returned: $result";
+		}
+	else{
+		$transcription ="Free Google Speech API returned, with a confidence of ".round($result['hypotheses'][0]['confidence']*100)."%";
+		$transcription.="\n".$result['hypotheses'][0]['utterance'];
+		}
+	return $transcription;
+	}
+
 //echo "raw message: \n".$email."\n";
 
 //if there is a carriage return remove it and standardize on line feed
@@ -161,6 +188,9 @@
 					$attachment_type = "audio/wav";
 					$attachment_ext = ".wav";
 					$attachment_str = trim(substr($mimepart, strlen($subheader), strlen($mimepart)));
+					
+					$transcription=get_transcription(base64_decode($attachment_str));
+					
 					//echo "\n*** begin wav ***\n".$attachment_str."\n*** end wav ***\n";
 				break;
 			case "audio/mp3;":
@@ -201,8 +231,8 @@
 	$mail->From       = $v_smtpfrom;
 	$mail->FromName   = $v_smtpfromname;
 	$mail->Subject    = $var['Subject'];
-	$mail->AltBody    = $textplain;   // optional, comment out and test
-	$mail->MsgHTML($texthtml);
+	$mail->AltBody    = $textplain."\n\n$transcription";   // optional, comment out and test
+	$mail->MsgHTML($texthtml."<br><br>".nl2br($transcription));
 
 
 	$v_to = $var['To'];

This SHOULD work for FusionPBX v3

Index: v_mailto.php
===================================================================
--- v_mailto.php        (revision 2811)
+++ v_mailto.php        (working copy)
@@ -54,6 +54,29 @@
        ob_end_clean();
        ob_start();

+function get_transcription($attachment_str){
+       $time=microtime(1);
+       $language="en-us";
+       $file_name="/tmp/vm_".$time;
+       file_put_contents($file_name.".wav",$attachment_str);
+       system("sox $file_name.wav $file_name.flac rate 16k");
+       $result=exec("wget -q -U 'Mozilla/5.0' --post-file $file_name.flac --header='Content-Type: audio/x-flac; rate=16000' -O - 'http://www.google.com/speech-api/v1/recognize?lang=$language&client=chromium'");
+       unlink($file_name.".wav");
+       unlink($file_name.".flac");
+
+       $result=json_decode($result,1);
+       if(!is_array($result['hypotheses'])){
+               $transcription ="Free Google Speech API returned: $result";
+               }
+       else{
+               $transcription ="Free Google Speech API returned, with a confidence of ".round($result['hypotheses'][0]['confidence']*100)."%";
+               $transcription.="\n".$result['hypotheses'][0]['utterance'];
+               }
+       return $transcription;
+       }
+
+
+
 //testing show the raw email
        //echo "Message: \n".$msg."\n";

@@ -209,13 +232,15 @@

                                //add an attachment
                                        $mail->AddStringAttachment($parts_array["Body"],$file,$encoding,$mime_type);
+                                        $attachments_array=$mail->GetAttachments();
+                                        $transcription=get_transcription($attachments_array[0]); //we shouldn't ever have more than one attachment
                        }
                }
        }

 //add the body to the email
-       $mail->AltBody    = $body_plain;   // optional, comment out and test
-       $mail->MsgHTML($body);
+       $mail->AltBody    = $body_plain."\n\n$transcription";
+       $mail->MsgHTML($body."<br><br>".nl2br($transcription));

 //send the email
        if(!$mail->Send()) {

Transcribing Voicemails with Nexiwave's free voicemail-to-text API

http://Nexiwave.com offers a free, fully automatic and much more accurate voicemail-to-text service.

For all FusionPBX versions

After registering your free Nexiwave account, simply configure FusionPBX to use your custom Nexiwave address:

Voicemail Mail To: joe_example.com@nexiwave.com

Nexiwave will receive, transcribe and send transcribed text (and audio) to joe@example.com.


No code change is required.

MWI

Some phones (Cisco SPA50x series for example) will forget about MWI when they reboot. This can be a real headache on provisioned phones. Thankfully, there is a fix for this.

mwi.lua

This program by default will notify all phones that have a voicemail on the system about it every 5 minutes. You should probably enable the debug options so you can verify that it's running.

You can find the program here:

/usr/local/freeswitch/scripts/app/voicemail/resources/scripts/mwi.lua

Enable Debug:

--debug
        debug["sql"] = true;
        debug["info"] = true;

starting

from fs_cli you can run

luarun app/voicemail/resources/scripts/mwi.lua

or from CLI

fs_cli -x 'luarun app/voicemail/resources/scripts/mwi.lua'

auto-starting

vim /usr/local/freeswitch/conf/autoload_configs/lua.conf.xml

And enable the script to auto-start

    <!--
        The following options identifies a lua script that is launched
        at startup and may live forever in the background.
        You can define multiple lines, one for each script you
        need to run.
    -->
    <param name="startup-script" value="app/voicemail/resources/scripts/mwi.lua"/>

Then restart FreeSWITCH

Notes

  • If the script is running you should notice the following file exists:
/usr/local/freeswitch/log/mwi.tmp
  • If you enabled debug, you'll also see info like the following in your freeswitch log:
2014-03-18 09:54:08.343349 [NOTICE] switch_cpp.cpp:1288 [voicemail] mailbox: 3161@192.168.1.4 messages: 3
2014-03-18 09:54:08.343349 [NOTICE] switch_cpp.cpp:1288 [voicemail] mailbox: 3103@192.168.1.4 messages: 2
2014-03-18 09:54:08.343349 [NOTICE] switch_cpp.cpp:1288 [voicemail] mailbox: 1342@192.168.1.4 messages: 1