Skip to content

Commit

Permalink
Ensure the local filename is unique per text/language
Browse files Browse the repository at this point in the history
  • Loading branch information
duncan3dc committed Nov 18, 2024
1 parent bdfaa80 commit 4d30cec
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Providers/PicottsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use function explode;
use function file_exists;
use function file_get_contents;
use function md5;
use function preg_match;
use function strlen;
use function strtolower;
Expand Down Expand Up @@ -128,7 +129,7 @@ public function getOptions(): array
*/
public function textToSpeech(string $text, FactoryInterface $factory = null): string
{
$filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "speaker_picotts.wav";
$filename = sys_get_temp_dir() . \DIRECTORY_SEPARATOR . "speaker_picotts_{$this->language}_" . md5($text) . ".wav";

if (file_exists($filename)) {
unlink($filename);
Expand Down
2 changes: 1 addition & 1 deletion tests/Providers/PicottsProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function testTextToSpeechError(): void
$this->result->shouldReceive("getStatus")->once()->with()->andReturn(0);

$this->expectException(ProviderException::class);
$this->expectExceptionMessage("TextToSpeech unable to create file: /tmp/speaker_picotts.wav");
$this->expectExceptionMessageMatches("/^TextToSpeech unable to create file: \/tmp\/speaker_picotts_en-US_[a-f0-9]{32}\.wav$/");
$provider->textToSpeech("Hello", $this->factory);
}

Expand Down

0 comments on commit 4d30cec

Please sign in to comment.