Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix argument in function to speak #3

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}