当前位置: 首页 > article >正文

Azure 将文本转换为语音

注意:只需要使用 speech 语音服务,不用Azure  OpenAi

环境变量

setx SPEECH_KEY your-key
setx SPEECH_REGION your-region

需要安装库

pip install azure-cognitiveservices-speech

import os
import azure.cognitiveservices.speech as speechsdk

# This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
speech_config = speechsdk.SpeechConfig(subscription=os.environ.get('SPEECH_KEY'), region=os.environ.get('SPEECH_REGION'))
audio_config = speechsdk.audio.AudioOutputConfig(use_default_speaker=True)

# The neural multilingual voice can speak different languages based on the input text.
speech_config.speech_synthesis_voice_name='en-US-AvaMultilingualNeural'

speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)

# Get text from the console and synthesize to the default speaker.
print("Enter some text that you want to speak >")
text = input()

speech_synthesis_result = speech_synthesizer.speak_text_async(text).get()

if speech_synthesis_result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
    print("Speech synthesized for text [{}]".format(text))
elif speech_synthesis_result.reason == speechsdk.ResultReason.Canceled:
    cancellation_details = speech_synthesis_result.cancellation_details
    print("Speech synthesis canceled: {}".format(cancellation_details.reason))
    if cancellation_details.reason == speechsdk.CancellationReason.Error:
        if cancellation_details.error_details:
            print("Error details: {}".format(cancellation_details.error_details))
            print("Did you set the speech resource key and region values?")

参见:

文本转语音快速入门 - 语音服务 - Azure AI services | Microsoft Learn

另一篇:

Azure OpenAI 语音转语音聊天_azure openai 语音转语音聊天 restful-CSDN博客


http://www.kler.cn/a/371508.html

相关文章:

  • 数据分析师入门: 数据分析可视化入门知识点
  • 量子容错计算
  • 八,Linux基础环境搭建(CentOS7)- 安装Mysql和Hive
  • NSSCTF刷题篇web部分
  • Java面向对象编程进阶(四)
  • Java Lock LockSupport 总结
  • this指针使用演示(C++)
  • Jetson AGX Orin 实现相机雷达联合标定
  • 用sdcc给51单片机编译C程序
  • 绿色制造中的 FMEA 系统的应用_SunFMEA软件
  • iOS Swift5算法恢复——HMAC
  • 『大模型笔记』如何在无网路的情况下在Linux主机上安装NVIDIA Container Toolkit(nvidia-docker2)
  • Nginx、Lua 和 Redis 架构来实现 IP 黑名单
  • 大话网络协议:HTTPS协议和HTTP协议有何不同?为什么HTTPS更安全
  • 014 安装DHCP服务器
  • Halcon相机外参自理解
  • Golang的多版本管理
  • VScode编译C++的配置文件
  • 今日总结10.29
  • 【Mac】Homebrew
  • Soanrquber集成Gitlab 之 gitlab用户配置和身份验证
  • 深度学习:Overfitting 成因及解决策略
  • UDP组播测试
  • 【c语言】运算符汇总(万字解析)
  • 基于安卓Android的健康饮食系统APP(源码+文档+部署+讲解)
  • 【力扣打卡系列】二分查找(红蓝染色法)