Skip to content

Commit

Permalink
feat: add speech marks in config
Browse files Browse the repository at this point in the history
  • Loading branch information
luigel committed Apr 10, 2021
1 parent 5fb6c4e commit 9011dda
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@
*/
'voice_id' => env('AWS_VOICE_ID', 'Amy'),

/**
* You can request any or all of the speech mark types, but leave it empty if you don't use speech marks.
* You may add any of the following:.
*
* sentence, word, viseme, ssml
*/
'speech_marks' => [],

/**
* IAM Credentials from AWS.
*/
Expand Down
18 changes: 16 additions & 2 deletions src/Converters/PollyConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ public function convert(string $data, array $options = null)
*/
protected function synthesizeSpeech($text, array $options = null)
{
$speechMarks = $this->getSpeechMarks();

$arguments = [
'LanguageCode' => $this->getLanguage(),
'VoiceId' => $this->voice($options),
'OutputFormat' => $this->format($options),
'TextType' => $this->textType(),
'SpeechMarkTypes' => $this->speechMarks,
'SpeechMarkTypes' => $speechMarks,
];

if (is_string($text)) {
Expand Down Expand Up @@ -204,6 +206,18 @@ protected function format($options)
return Arr::get($options, 'format', $default);
}

/**
* Get the speech marks.
*
* @return array
*/
protected function getSpeechMarks()
{
$default = config('tts.services.polly.speech_marks', []);

return ! empty($this->speechMarks) ? $this->speechMarks : $default;
}

/**
* Get the content of the result from AWS Polly.
*
Expand All @@ -222,7 +236,7 @@ protected function getResultContent($result)
*/
protected function hasSpeechMarks()
{
return ! empty($this->speechMarks);
return ! empty($this->getSpeechMarks());
}

/**
Expand Down

0 comments on commit 9011dda

Please sign in to comment.