PHP Classes

File: examples/Voice/index.php

Recommend this page to a friend!
  Classes of MERAJ AHMAD SIDDIQUI   PHP IBM Watson   examples/Voice/index.php   Download  
File: examples/Voice/index.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP IBM Watson
Call IBM Watson API services
Author: By
Last change:
Date: 6 years ago
Size: 1,092 bytes
 

Contents

Class file image Download
<?php

include dirname(dirname(__DIR__)) . "/vendor/autoload.php";
//Provide jspn file to config
use IBMWatson\Config;
//json file containing url, username and password for the service
$api_credintial_json_file = dirname(dirname(__DIR__)) . "/config/text_to_speech.json";
$config = Config::init($api_credintial_json_file);
/**
 * Service To be used
 */

use IBMWatson\Speech\TextToSpeech;
//provide configuration to service
$voice = new TextToSpeech\Voice($config);
//Use method availables in voice
$available_voices = $voice->getAvailableVoice();
//filter_voice
$filter_by = ["gender" => "female", "language" => "en-US"];
//Above options will be used to find the appropriate voice
$filtered_voice = $voice->filterVoice($filter_by);
//get default voice for watson
$default_voice = $voice->getDefaultVoice();
//Setting desired output for voice
$voice->setPersonVoice($filtered_voice[0]);
//Text which will be converted to audio
$text_content = "Hi Meraj, How are you doing today?";
//calling audio function to convert to audio
$audio = $voice->createAudio($text_content);
var_dump($audio);

?>