Spaces:
Sleeping
Sleeping
File size: 1,464 Bytes
aca9481 3281c07 aca9481 3281c07 aca9481 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
#!/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()
|