The TTS (Text-to-Speech) API uses advanced speech synthesis technology to convert text into natural, fluent human voices, supporting multiple languages and voice options.
import openaifrom pathlib import Pathclient = openai.OpenAI( api_key="YOUR_API_KEY", base_url="https://ai.kaiho.cc/v1")# Generate speechresponse = client.audio.speech.create( model="tts-1-hd", voice="nova", input="Welcome to Kaihoxz text-to-speech service. We provide the most natural AI voice synthesis technology.", speed=1.0)# Save to filespeech_file_path = Path("speech.mp3")response.stream_to_file(speech_file_path)print(f"Speech saved to: {speech_file_path}")
Usage Guidelines: Please ensure that generated speech content complies with local laws and regulations. It must not be used for fraud, impersonation, or other illegal purposes.
Performance Optimization: For real-time applications, use the tts-1 model with opus format to achieve the lowest latency.