首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何以编程方式将阿塞拜疆文本转换为语音?

如何以编程方式将阿塞拜疆文本转换为语音?
EN

Stack Overflow用户
提问于 2020-01-28 16:36:26
回答 1查看 59关注 0票数 1

我们有一个转换阿塞拜疆文本到语音编程的需要。有没有(最好是免费的)库或服务可以将文本转换成语音?

EN

回答 1

Stack Overflow用户

发布于 2020-01-28 20:58:24

联系https://azreco.az/他们是有魔力的人。

代码示例是here,例如PHP:

代码语言:javascript
复制
<?php
class Synthesizer {

    function __construct($input_type, $api_id, $api_token, $lang, $output,
                            $api_url_file='http://api.azreco.az/synthesize',
                                $api_url_text='http://api.azreco.az/synthesize/text') {
        $this->input_type = $input_type;
        $this->api_id = $api_id;
        $this->api_token = $api_token;
        $this->lang = $lang;
        $this->api_url_file = $api_url_file;
        $this->api_url_text = $api_url_text;
        $this->output = $output;
    }

    function synthesize($opts) {
        $params = array(
            "api_id" => $this->api_id,
            "api_token" => $this->api_token,
            "lang" => $this->lang,
        );

        $ch = curl_init();

        if($this->input_type == "file") {
            $file_path = realpath($opts);
            $params['file'] = new cURLFile($file_path);
            curl_setopt($ch, CURLOPT_URL, $this->api_url_file);
        } elseif($this->input_type == "text") {
            $params["text"] = $opts;
            curl_setopt($ch, CURLOPT_URL, $this->api_url_text);
        } else {
            throw new Exception("Type of input. Must be one of 'text' or 'file'.");
        }

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        $data = curl_exec($ch);

        if (!curl_errno($ch)) {
            $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            if ($http_code == 200) {
                file_put_contents($this->output, $data);
                echo "File saved! \n";
            } else {
                echo $data . "\n";
                echo 'Unexpected HTTP code: ', $http_code, "\n";
            }
        }
        curl_close($ch);
    }
}

$opts = "t:l:i:k:o:";
$longopts  = array("input-type:",);
$options = getopt($opts, $longopts);

$synth = new Synthesizer($options['input-type'],$options['i'], $options['k'], $options['l'], $options['o']);
$synth->synthesize($options['t']);

?>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59944829

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档