Example #1
0
 /**
  * @param ResourceDOInterface $resourceDO
  * @return mixed
  * @throws ErrorException
  */
 protected function generate(ResourceDOInterface $resourceDO)
 {
     /** @var Manager $generator */
     $generator = $this->generator;
     // If a body is exist, it will be used as the text for voicing
     $body = $resourceDO->getBody();
     // If an alternative name is exist, it will be used when body is empty
     $alternative = $resourceDO->getNameAlternative();
     // The main resource name will be used, if no body and no alt exist
     $voiceText = $body ?: ($alternative ?: $resourceDO->getName());
     $this->selectLanguage($voiceText);
     $content = $generator->read($voiceText);
     $headers = $generator->getHeaders();
     if (!array_key_exists('http_code', (array) $headers) || $headers['http_code'] != 200) {
         throw new ErrorException('Wrong http response code from voice provider ' . get_class($this->generator->getAdapter()) . ': ' . $headers['http_code'] . '; Requested text: ' . $resourceDO->getName());
     }
     return $content;
 }