Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex SpeechKit
  • SpeechKit technology overview
    • About the Python SDK
    • Installing the Python SDK
    • Resolving version conflicts during the installation of Python SDK
    • Authentication in the Python SDK
    • Synchronous recognition using the Python SDK
    • Speech synthesis using the Python SDK
  • Supported audio formats
  • IVR integration
  • Quotas and limits
  • Access management
  • Pricing policy

In this article:

  • Getting started
  • Create an application for speech synthesis
  1. SDK
  2. Speech synthesis using the Python SDK

Speech synthesis using the Python SDK

Written by
Yandex Cloud
Updated at April 24, 2025
  • Getting started
  • Create an application for speech synthesis

Below is an example of speech synthesis from text in TTS markup into a WAV file using the SpeechKit Python SDK. This example uses the following parameters:

  • Voice: jane.
  • Role: good.

The other speech synthesis settings are at their defaults.

To use the Python SDK, the yandex-speechkit package is required.

Authentication is performed under a service account using an API key or IAM token. Learn more about authentication in the SpeechKit API.

Getting startedGetting started

  1. Create a service account and assign the ai.speechkit-tts.user role to it.
  2. Get an API key for the service account and save it.

Create an application for speech synthesisCreate an application for speech synthesis

Python 3
  1. Install the yandex-speechkit package using the pip package manager:

    pip install yandex-speechkit
    

    The installation was tested on Python 3.9. For the minimum allowed Python version, see the SDK website.

    If a grpcio-tools package version conflict occurs, see Resolving version conflicts during the installation of Python SDK.

  2. Create a file named test.py and add the following code to it:

    from argparse import ArgumentParser
    
    from speechkit import model_repository, configure_credentials, creds
    
    # Authentication with an API key.
    configure_credentials(
       yandex_credentials=creds.YandexCredentials(
          api_key='<API_key>'
       )
    )
    
    def synthesize(text, export_path):
       model = model_repository.synthesis_model()
    
       # Specify the synthesis settings.
       model.voice = 'jane'
       model.role = 'good'
    
       # Performing speech synthesis and creating the output audio file.
       result = model.synthesize(text, raw_format=False)
       result.export(export_path, 'wav')
    
    if __name__ == '__main__':
       parser = ArgumentParser()
       parser.add_argument('--text', type=str, help='text to synthesize', required=True)
       parser.add_argument('--export', type=str, help='export path for synthesized audio', required=False)
    
       args = parser.parse_args()
    
       synthesize(args.text, args.export)
    

    Where:

    • api_key: Service account API key.
    • voice: Voice for speech synthesis.
    • role: Role for the specified voice.
    • text: Text for synthesis in TTS markup.
    • export_path: Path to the file to save the audio to.
  3. Save the text to convert to speech into an environment variable:

    export TEXT='I'm Yandex Speech+Kit. I can turn any text into speech. Now y+ou can, too!'
    
  4. Run the created file:

    python3 test.py --text ${TEXT} --export speech.wav
    

    Where:

    • --text: Text for synthesis in TTS markup. In the example, the text is provided in the TEXT environment variable.
    • --export: Path to the file to save the audio to.

    This will create the speech.wav file with synthesized speech.

See alsoSee also

  • Python SDK SpeechKit
  • Speech synthesis in the API v3

Was the article helpful?

Previous
Synchronous recognition using the Python SDK
Next
All tutorials
Yandex project
© 2025 Yandex.Cloud LLC