Spaces:
Running
Running
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
""" | |
https://platform.openai.com/docs/guides/text-to-speech | |
""" | |
import argparse | |
from pathlib import Path | |
from openai import OpenAI | |
from project_settings import environment, project_path | |
def get_args(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
"--openai_model", | |
default="tts-1", | |
choices=["tts-1"], | |
type=str | |
) | |
parser.add_argument( | |
"--openai_voice", | |
default="alloy", | |
choices=["alloy", "nova"], | |
type=str | |
) | |
parser.add_argument( | |
"--openai_input", | |
# default="Today is a wonderful day to build something people love!", | |
default="μ€λμ μ¬λλ€μ΄ μ’μνλ κ²μ λ§λ€κΈ°μ μ’μ λ μ λλ€!", | |
type=str | |
) | |
parser.add_argument( | |
"--speech_file_path", | |
default=(Path(__file__).parent / "speech_alloy_korean.mp3").as_posix(), | |
type=str | |
) | |
parser.add_argument( | |
"--openai_api_key", | |
default=environment.get("openai_api_key", default=None, dtype=str), | |
type=str | |
) | |
args = parser.parse_args() | |
return args | |
def main(): | |
args = get_args() | |
client = OpenAI() | |
response = client.audio.speech.create( | |
model=args.openai_model, | |
voice=args.openai_voice, | |
input=args.openai_input, | |
) | |
response.stream_to_file(args.speech_file_path) | |
return | |
if __name__ == '__main__': | |
main() | |