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 9 months ago
parent ebf052b766
commit e8f90dc8b2

@ -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
@ -20,13 +20,12 @@ to improve.
*/
$apiKey="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$apiURL="https://api.us-south.speech-to-text.watson.cloud.ibm.com/instances/xxxxxxxxxxxxxxxxxxxxxxxxx";
$apiURLRecognize="/v1/recognize?model=en-US_Telephony";
$apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$apiURL = "https://api.us-south.speech-to-text.watson.cloud.ibm.com/instances/xxxxxxxxxxxxxxxxxxxxxxxxx";
$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);
$wavFile = mailparse_msg_extract_part($mimePart, $emailRaw, null);
$textMsg = mailparse_msg_extract_part($textPart, $emailRaw, null);
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 .= "\n\nSpeech To Text (May be inaccurate!):\n\n";
$textMsg = mailparse_msg_extract_part($textPart, $emailRaw, null);
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,21 +104,23 @@ if (isset($mailData['headers']['content-language'])) {
$sendMimeMail = new Mail_mime();
$sendMimeMail->setTXTBody($textMsg);
$sendMimeMail->addAttachment(
$wavFile,
$mimePartHeader['content-type'],
$mimePartHeader['content-name'],
false,
'base64',
'attachment',
null,
null,
null,
null,
null,
$mimePartHeader['content-description'],
null
);
if (isset($wavFile)) {
$sendMimeMail->addAttachment(
$wavFile,
$mimePartHeader['content-type'],
$mimePartHeader['content-name'],
false,
'base64',
'attachment',
null,
null,
null,
null,
null,
$mimePartHeader['content-description'],
null
);
}
$mailBody = $sendMimeMail->get();
$mailHeaders = $sendMimeMail->headers($headers);
$sendMail = Mail::factory("sendmail");

Loading…
Cancel
Save