语音识别API - 实现文字转语音

2022-03-29 13:45:02 浏览数 (1)

目录

搜狗(目前好用,免费)

百度(现在收费了,送一定额度)

腾讯(收费的)

搜狗(目前好用,免费)

代码语言:javascript复制
    def textToAudio_Sougou(message, filePath):
        # https://ai.so    gou.com/doc/?url=/docs/content/tts/references/rest/ 
        '''
        curl -X POST 
             -H "Content-Type: application/json" 
             --data '{
          "appid": "xxx",
          "appkey": "xxx",
          "exp": "3600s"
        }' https://api.zhiyin.sogou.com/apis/auth/v1/create_token
        '''

        token = 'xxx'
        headers = { 
            'Authorization' : 'Bearer ' token,
            'Appid' : 'xxx',
            'Content-Type' : 'application/json',
            'appkey' : 'xxx',
            'secretkey' : 'xxx'
        }
        data = {
          'input': {
            'text': message
          },
          'config': {
            'audio_config': {
              'audio_encoding': 'LINEAR16',
              'pitch': 1.0,
              'volume': 1.0,
              'speaking_rate': 1.0
            },
            'voice_config': {
              'language_code': 'zh-cmn-Hans-CN',
              'speaker': 'female'
            }
          }
        }
        
        result = requests.post(url=url, headers=headers, data=json.dumps(data, ensure_ascii=False).encode('utf-8')).content
        with open(filePath, 'wb') as f:
            f.write(result)

百度(现在收费了,送一定额度)

腾讯(收费的)

0 人点赞