Some minor error checking, needs way more work, but I'm a little happier with its response to things not being like it expects

master
Brie Bruns 2022-05-20 10:38:02 -06:00
parent ebf052b766
commit e8f90dc8b2
1 changed files with 33 additions and 27 deletions

View File

@ -4,8 +4,8 @@
/*
Asterisk Voicemail Transcribe Wrapper
Version: 0.6.1
Date: 5/18/2022
Version: 0.7.0
Date: 5/20/2022
License: This work is licensed under CC BY-SA 4.0
URL: https://git.sosdg.org/brielle/asterisk-scripts
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);
require_once ("Mail.php");
require_once ("Mail/mime.php");
@ -34,16 +33,21 @@ $mail = mailparse_msg_create();
mailparse_msg_parse($mail, $emailRaw);
$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);
}
}
$textMsg = mailparse_msg_extract_part($textPart, $emailRaw, null);
$textMsg .= "\n\nSpeech To Text (May be inaccurate!):\n\n";
if (isset($wavFile)) {
$textMsg .= "\n\nSpeech To Text (May be inaccurate!):\n\n";
$submitWatsonSTT=curl_init();
curl_setopt_array($submitWatsonSTT, array(
CURLOPT_CONNECTTIMEOUT => '15',
@ -100,6 +104,7 @@ if (isset($mailData['headers']['content-language'])) {
$sendMimeMail = new Mail_mime();
$sendMimeMail->setTXTBody($textMsg);
if (isset($wavFile)) {
$sendMimeMail->addAttachment(
$wavFile,
$mimePartHeader['content-type'],
@ -115,6 +120,7 @@ $sendMimeMail->addAttachment(
$mimePartHeader['content-description'],
null
);
}
$mailBody = $sendMimeMail->get();
$mailHeaders = $sendMimeMail->headers($headers);
$sendMail = Mail::factory("sendmail");