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
|
||||||
|
@ -26,7 +26,6 @@ $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);
|
|
||||||
|
|
||||||
|
$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);
|
$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,6 +104,7 @@ if (isset($mailData['headers']['content-language'])) {
|
||||||
|
|
||||||
$sendMimeMail = new Mail_mime();
|
$sendMimeMail = new Mail_mime();
|
||||||
$sendMimeMail->setTXTBody($textMsg);
|
$sendMimeMail->setTXTBody($textMsg);
|
||||||
|
if (isset($wavFile)) {
|
||||||
$sendMimeMail->addAttachment(
|
$sendMimeMail->addAttachment(
|
||||||
$wavFile,
|
$wavFile,
|
||||||
$mimePartHeader['content-type'],
|
$mimePartHeader['content-type'],
|
||||||
|
@ -115,6 +120,7 @@ $sendMimeMail->addAttachment(
|
||||||
$mimePartHeader['content-description'],
|
$mimePartHeader['content-description'],
|
||||||
null
|
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