-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_voice.py
More file actions
32 lines (23 loc) · 1.3 KB
/
Copy pathgenerate_voice.py
File metadata and controls
32 lines (23 loc) · 1.3 KB
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
from pathlib import Path
from dotenv import load_dotenv
from openai_client import openai_client
load_dotenv()
client = openai_client()
def generateVoice(title, speech, voice):
# Split the text into chunks of at most 4096 characters
chunk_size = 4096
chunks = [speech[i:i + chunk_size] for i in range(0, len(speech), chunk_size)]
speech_file_path = Path(__file__).parent / "output" / "audio" / title
# Create speech for each chunk and append to the output file
with open(speech_file_path, "wb") as f:
for chunk in chunks:
response = client.audio.speech.create(
model="tts-1",
speed=1,
voice=voice,
input=chunk,
)
f.write(response.content)
print("\n\033[94mSpeech generation complete.\033[0m\n")
# generateVoice("sample.mp3", """As you embark on your dopamine detox journey, you'll find yourself confronting the discomfort of withdrawal. The first few hours may feel like an eternity as your mind yearns for its usual dopamine fix. You'll reach for your phone out of habit, only to remember your commitment to disconnect. It's in these moments of craving that you'll truly understand the hold dopamine has over your life.
# But as the day progresses, something remarkable happens.""", "onyx")