Created
August 12, 2024 13:06
-
-
Save tbg/dc6e26bd4404fe234c4a47a8c4899f98 to your computer and use it in GitHub Desktop.
openai-text-to-speech.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
from openai import OpenAI | |
client = OpenAI() | |
input_file_path = Path(__file__).parent / "input.txt" | |
with open(input_file_path, 'r') as f: | |
paragraphs = f.read().split('\n\n') | |
for i, input in enumerate(paragraphs): | |
response = client.audio.speech.create( | |
model="tts-1", | |
voice="alloy", | |
input=input | |
) | |
speech_file_path = Path(__file__).parent / f"output-{i+1}.mp3" | |
response.stream_to_file(speech_file_path) | |
print(speech_file_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment