kxxt / aspeak

A simple text-to-speech client for Azure TTS API.
MIT License
494 stars 57 forks source link

Add a few stuffs that might be useful while using aspeak as a library. #20

Closed EverythingSuckz closed 2 years ago

EverythingSuckz commented 2 years ago

Example usage:

from azure.cognitiveservices.speech import ResultReason, audio
from aspeak import SpeechServiceProvider, text_to_speech, AudioFormat, FileFormat, AspeakError

if __name__ == "__main__":
    try:
        output = audio.AudioOutputConfig(use_default_speaker=True)
        provider = SpeechServiceProvider()
        result = text_to_speech(provider, output, "Hello World! I am using aspeak to synthesize speech.", use_async=True,
                                voice="en-US-JennyNeural", rate="+10%", pitch="-5%", style="cheerful",
                                audio_format=AudioFormat(FileFormat.WAV, 1))
        print("Synthesis started and the workflow isn't blocked.")
        result = result.get() # Wait for the synthesis to complete
        if result.reason != ResultReason.SynthesizingAudioCompleted:
            print("Failed to synthesize speech.")
    except AspeakError:
        print("Error occurred while synthesizing speech.")