Some minor error checking, needs way more work, but I'm a little happier with its response to things not being like it expects
parent
ebf052b766
commit
e8f90dc8b2
|
@ -4,8 +4,8 @@
|
||||||
/*
|
/*
|
||||||
|
|
||||||
Asterisk Voicemail Transcribe Wrapper
|
Asterisk Voicemail Transcribe Wrapper
|
||||||
Version: 0.6.1
|
Version: 0.7.0
|
||||||
Date: 5/18/2022
|
Date: 5/20/2022
|
||||||
License: This work is licensed under CC BY-SA 4.0
|
License: This work is licensed under CC BY-SA 4.0
|
||||||
URL: https://git.sosdg.org/brielle/asterisk-scripts
|
URL: https://git.sosdg.org/brielle/asterisk-scripts
|
||||||
Requires: PHP 5 or 7, Mail and Mail_Mime libraries from Pear
|
Requires: PHP 5 or 7, Mail and Mail_Mime libraries from Pear
|
||||||
|
@ -20,13 +20,12 @@ to improve.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
$apiKey="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
$apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
|
||||||
$apiURL="https://api.us-south.speech-to-text.watson.cloud.ibm.com/instances/xxxxxxxxxxxxxxxxxxxxxxxxx";
|
$apiURL = "https://api.us-south.speech-to-text.watson.cloud.ibm.com/instances/xxxxxxxxxxxxxxxxxxxxxxxxx";
|
||||||
$apiURLRecognize="/v1/recognize?model=en-US_Telephony";
|
$apiURLRecognize = "/v1/recognize?model=en-US_Telephony";
|
||||||
|
|
||||||
$emailRaw = stream_get_contents(STDIN);
|
$emailRaw = stream_get_contents(STDIN);
|
||||||
|
|
||||||
|
|
||||||
require_once ("Mail.php");
|
require_once ("Mail.php");
|
||||||
require_once ("Mail/mime.php");
|
require_once ("Mail/mime.php");
|
||||||
|
|
||||||
|
@ -34,16 +33,21 @@ $mail = mailparse_msg_create();
|
||||||
mailparse_msg_parse($mail, $emailRaw);
|
mailparse_msg_parse($mail, $emailRaw);
|
||||||
|
|
||||||
$mailData=mailparse_msg_get_part_data($mail);
|
$mailData=mailparse_msg_get_part_data($mail);
|
||||||
$textPart = mailparse_msg_get_part($mail, "1.1");
|
|
||||||
$mimePart = mailparse_msg_get_part($mail, "1.2");
|
|
||||||
$mimePartHeader = mailparse_msg_get_part_data($mimePart);
|
|
||||||
|
|
||||||
$wavFile = mailparse_msg_extract_part($mimePart, $emailRaw, null);
|
$textPart = mailparse_msg_get_part($mail, "1.1");
|
||||||
|
|
||||||
|
if (mailparse_msg_get_structure($mail)[2] == "1.2") {
|
||||||
|
$mimePart = mailparse_msg_get_part($mail, "1.2");
|
||||||
|
if (mailparse_msg_get_part_data($mimePart)['content-type'] == "audio/x-wav") {
|
||||||
|
$mimePartHeader = mailparse_msg_get_part_data($mimePart);
|
||||||
|
$wavFile = mailparse_msg_extract_part($mimePart, $emailRaw, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$textMsg = mailparse_msg_extract_part($textPart, $emailRaw, null);
|
$textMsg = mailparse_msg_extract_part($textPart, $emailRaw, null);
|
||||||
|
|
||||||
$textMsg .= "\n\nSpeech To Text (May be inaccurate!):\n\n";
|
|
||||||
|
|
||||||
if (isset($wavFile)) {
|
if (isset($wavFile)) {
|
||||||
|
$textMsg .= "\n\nSpeech To Text (May be inaccurate!):\n\n";
|
||||||
$submitWatsonSTT=curl_init();
|
$submitWatsonSTT=curl_init();
|
||||||
curl_setopt_array($submitWatsonSTT, array(
|
curl_setopt_array($submitWatsonSTT, array(
|
||||||
CURLOPT_CONNECTTIMEOUT => '15',
|
CURLOPT_CONNECTTIMEOUT => '15',
|
||||||
|
@ -100,21 +104,23 @@ if (isset($mailData['headers']['content-language'])) {
|
||||||
|
|
||||||
$sendMimeMail = new Mail_mime();
|
$sendMimeMail = new Mail_mime();
|
||||||
$sendMimeMail->setTXTBody($textMsg);
|
$sendMimeMail->setTXTBody($textMsg);
|
||||||
$sendMimeMail->addAttachment(
|
if (isset($wavFile)) {
|
||||||
$wavFile,
|
$sendMimeMail->addAttachment(
|
||||||
$mimePartHeader['content-type'],
|
$wavFile,
|
||||||
$mimePartHeader['content-name'],
|
$mimePartHeader['content-type'],
|
||||||
false,
|
$mimePartHeader['content-name'],
|
||||||
'base64',
|
false,
|
||||||
'attachment',
|
'base64',
|
||||||
null,
|
'attachment',
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
$mimePartHeader['content-description'],
|
null,
|
||||||
null
|
$mimePartHeader['content-description'],
|
||||||
);
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
$mailBody = $sendMimeMail->get();
|
$mailBody = $sendMimeMail->get();
|
||||||
$mailHeaders = $sendMimeMail->headers($headers);
|
$mailHeaders = $sendMimeMail->headers($headers);
|
||||||
$sendMail = Mail::factory("sendmail");
|
$sendMail = Mail::factory("sendmail");
|
||||||
|
|
Loading…
Reference in New Issue