8000 Initial implementation · Issue #1 · simonw/ospeak · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Initial implementation #1
Closed
Closed
@simonw

Description

@simonw

I'm going to base this on the example from https://platform.openai.com/docs/guides/text-to-speech

import io
from openai import OpenAI
from pydub import AudioSegment
from pydub.playback import play

client = OpenAI()


def stream_and_play(text):
    response = client.audio.speech.create(
        model="tts-1",
        voice="alloy",
        input=text,
    )

    # Convert the binary response content to a byte stream
    byte_stream = io.BytesIO(response.content)

    # Read the audio data from the byte stream
    audio = AudioSegment.from_file(byte_stream, format="mp3")

    # Play the audio
    play(audio)


if __name__ == "__main__":
    text = input("Enter text: ")
    stream_and_play(text)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0