Skip to content

Commit

Permalink
Change a few things in the AWS Polly integration to take advantage of…
Browse files Browse the repository at this point in the history
… the changes made in the TTS feature, standardizing on how all these providers work
  • Loading branch information
dkotter committed Apr 1, 2024
1 parent c890d8f commit 76d83b7
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions includes/Classifai/Providers/AWS/AmazonPolly.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
namespace Classifai\Providers\AWS;

use Classifai\Providers\Provider;
use Classifai\Normalizer;
use Classifai\Features\TextToSpeech;
use WP_Error;
use Aws\Sdk;
Expand All @@ -18,14 +17,6 @@ class AmazonPolly extends Provider {

const ID = 'aws_polly';

/**
* Meta key to get/set the audio hash that helps to indicate if there is any need
* for the audio file to be regenerated or not.
*
* @var string
*/
const AUDIO_HASH_KEY = '_classifai_post_audio_hash';

/**
* AmazonPolly Text to Speech constructor.
*
Expand Down Expand Up @@ -374,12 +365,10 @@ public function synthesize_speech( int $post_id ) {
);
}

$normalizer = new Normalizer();
$feature = new TextToSpeech();
$settings = $feature->get_settings();
$post = get_post( $post_id );
$post_content = $normalizer->normalize_content( $post->post_content, $post->post_title, $post_id );
$content_hash = get_post_meta( $post_id, self::AUDIO_HASH_KEY, true );
$post_content = $feature->normalize_post_content( $post_id );
$content_hash = get_post_meta( $post_id, TextToSpeech::AUDIO_HASH_KEY, true );
$saved_attachment_id = (int) get_post_meta( $post_id, $feature::AUDIO_ID_KEY, true );

// Don't regenerate the audio file it it already exists and the content hasn't changed.
Expand Down Expand Up @@ -453,7 +442,7 @@ public function synthesize_speech( int $post_id ) {
$polly_client = $this->get_polly_client();
$result = $polly_client->synthesizeSpeech( $synthesize_data );

update_post_meta( $post_id, self::AUDIO_HASH_KEY, md5( $post_content ) );
update_post_meta( $post_id, TextToSpeech::AUDIO_HASH_KEY, md5( $post_content ) );
$contents = $result['AudioStream']->getContents();
return $contents;
} catch ( \Exception $e ) {
Expand Down

0 comments on commit 76d83b7

Please sign in to comment.