Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuj Sharma committed May 21, 2018
1 parent 6f53fdd commit a9edb01
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/WatsonTts.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct($watson_username, $watson_password, $watson_url = nu
$this->WATSON_PASSWORD = $watson_password;

if (!empty($watson_url)) {
$this->WATSON_URL = $watson_url;
$this->_prepareWatsonUrl($watson_url);
}
}

Expand Down Expand Up @@ -214,6 +214,8 @@ private function processWatsonTtsCurl()

$text_json = json_encode($text_data);

$output_file = fopen($this->output_file_path, 'w');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->WATSON_URL);
curl_setopt($ch, CURLOPT_USERPWD, $this->WATSON_USERNAME.':'.$this->WATSON_PASSWORD);
Expand All @@ -224,6 +226,7 @@ private function processWatsonTtsCurl()
'Accept: audio/'.$this->audio_format,
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $text_json);
curl_setopt($ch, CURLOPT_FILE, $output_file);

$result = curl_exec($ch);
if (curl_errno($ch)) {
Expand All @@ -234,4 +237,14 @@ private function processWatsonTtsCurl()
print_r($result);
}

private function _prepareWatsonUrl($watson_url)
{
$trim_url = rtrim($watson_url, '/');

if (strpos($trim_url, '/v1/synthesize') !== false)
$this->WATSON_URL = $trim_url;
else
$this->WATSON_URL = rtrim($watson_url, '/').'/v1/synthesize';
}

}

0 comments on commit a9edb01

Please sign in to comment.