Skip to content

Commit

Permalink
fix argument in function to speak
Browse files Browse the repository at this point in the history
Signed-off-by: Crisciany Silva <[email protected]>
  • Loading branch information
Any97Cris committed Feb 27, 2024
1 parent 432108c commit 41ada86
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/Espeak.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class Espeak
{
use QuoteStringTrait;

private InputOptions $inputOptions;
public function __construct()
{
Expand Down Expand Up @@ -34,7 +36,7 @@ public function execute(string $argument = ''): string
}
$cmd = 'espeak-ng' . $options;
if (strlen($argument) > 0) {
$cmd .= ' ' . $argument;
$cmd .= ' ' . $this->quoteString($argument);
}
$output = \shell_exec($cmd);
return $output;
Expand Down
11 changes: 2 additions & 9 deletions src/InputOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class InputOptions implements Stringable
{
use QuoteStringTrait;

private array $options = [];
public function setOption(string $name, ?string $value = null)
{
Expand All @@ -17,15 +19,6 @@ public function hasOption(string $name)
return array_key_exists($name, $this->options);
}

private function quoteString(string $value): string
{
$value = str_replace('"', '\"', $value);
if (str_contains($value, ' ')) {
$value = '"' . $value . '"';
}
return $value;
}

private function nameValueToString(string $name, array $values, string $separator, string $type)
{
$return = [];
Expand Down
15 changes: 15 additions & 0 deletions src/QuoteStringTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Libresign\Espeak;

trait QuoteStringTrait
{
public function quoteString(string $value): string
{
$value = str_replace('"', '\"', $value);
if (str_contains($value, ' ')) {
$value = '"' . $value . '"';
}
return $value;
}
}

0 comments on commit 41ada86

Please sign in to comment.