Difference between revisions of "Voicemail"

From FusionPBX
Jump to: navigation, search
(Multiple Email)
(google speech api)
Line 35: Line 35:
 
===Why?===
 
===Why?===
 
Sending MMS messages to mobile phones without email plans is one reason.
 
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.
 +
 +
[http://wiki.openmoko.org/wiki/Google_Voice_Recognition#Google_Voice_API this] showed me the basics of how to do this.
 +
 +
<pre>
 +
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'];
 +
 +
</pre>

Revision as of 21:55, 6 December 2011

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.

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'];