Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -45,7 +45,9 @@ speakers = {
|
|
45 |
}
|
46 |
|
47 |
def generateAudio(text_to_audio, s3_save_as):
|
48 |
-
|
|
|
|
|
49 |
def cut_text(text, max_tokens=500):
|
50 |
# Remove non-alphanumeric characters, except periods and commas
|
51 |
text = re.sub(r"[^\w\s.,]", "", text)
|
@@ -57,14 +59,14 @@ def generateAudio(text_to_audio, s3_save_as):
|
|
57 |
cut = ' '.join(tokens[:max_tokens])
|
58 |
return cut
|
59 |
|
60 |
-
def save_audio_to_s3(audio
|
61 |
# Create an instance of the S3 client
|
62 |
s3 = boto3.client('s3',
|
63 |
aws_access_key_id=AWS_ACCESS_KEY_ID,
|
64 |
aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
|
65 |
|
66 |
# Full path of the file in the bucket
|
67 |
-
s3_key = "public/" +
|
68 |
|
69 |
# Upload the audio file to the S3 bucket
|
70 |
s3.upload_fileobj(audio, S3_BUCKET_NAME, s3_key)
|
@@ -84,14 +86,7 @@ def generateAudio(text_to_audio, s3_save_as):
|
|
84 |
# generate speech with the models
|
85 |
speech = model.generate_speech(
|
86 |
inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
|
87 |
-
|
88 |
-
# if we have a speaker, we use the speaker's ID in the filename
|
89 |
-
output_filename = f"{speaker}-{'-'.join(text.split()[:6])}.wav"
|
90 |
-
else:
|
91 |
-
# if we don't have a speaker, we use a random string in the filename
|
92 |
-
random_str = ''.join(random.sample(
|
93 |
-
string.ascii_letters+string.digits, k=5))
|
94 |
-
output_filename = f"{random_str}-{'-'.join(text.split()[:6])}.wav"
|
95 |
# create BytesIO object to store the audio
|
96 |
audio_buffer = BytesIO()
|
97 |
# save the generated speech to the BytesIO buffer
|
@@ -99,14 +94,12 @@ def generateAudio(text_to_audio, s3_save_as):
|
|
99 |
audio_buffer.seek(0)
|
100 |
|
101 |
# Save the audio to S3
|
102 |
-
save_audio_to_s3(audio_buffer
|
103 |
-
|
104 |
-
# return the filename for reference
|
105 |
-
return output_filename
|
106 |
-
|
107 |
-
output_filename = save_text_to_speech(text_to_audio, "clb")
|
108 |
|
109 |
-
|
|
|
|
|
110 |
|
111 |
-
iface = gr.Interface(fn=generateAudio, inputs=[Textbox(label="text_to_audio"), Textbox(label="
|
|
|
112 |
iface.launch()
|
|
|
45 |
}
|
46 |
|
47 |
def generateAudio(text_to_audio, s3_save_as):
|
48 |
+
|
49 |
+
s3_save_as = '-'.join(save_as.split()) + ".wav"
|
50 |
+
|
51 |
def cut_text(text, max_tokens=500):
|
52 |
# Remove non-alphanumeric characters, except periods and commas
|
53 |
text = re.sub(r"[^\w\s.,]", "", text)
|
|
|
59 |
cut = ' '.join(tokens[:max_tokens])
|
60 |
return cut
|
61 |
|
62 |
+
def save_audio_to_s3(audio):
|
63 |
# Create an instance of the S3 client
|
64 |
s3 = boto3.client('s3',
|
65 |
aws_access_key_id=AWS_ACCESS_KEY_ID,
|
66 |
aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
|
67 |
|
68 |
# Full path of the file in the bucket
|
69 |
+
s3_key = "public/" + s3_save_as
|
70 |
|
71 |
# Upload the audio file to the S3 bucket
|
72 |
s3.upload_fileobj(audio, S3_BUCKET_NAME, s3_key)
|
|
|
86 |
# generate speech with the models
|
87 |
speech = model.generate_speech(
|
88 |
inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
|
89 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
# create BytesIO object to store the audio
|
91 |
audio_buffer = BytesIO()
|
92 |
# save the generated speech to the BytesIO buffer
|
|
|
94 |
audio_buffer.seek(0)
|
95 |
|
96 |
# Save the audio to S3
|
97 |
+
save_audio_to_s3(audio_buffer)
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
+
save_text_to_speech(text_to_audio, 2271)
|
100 |
+
return s3_save_as
|
101 |
+
|
102 |
|
103 |
+
iface = gr.Interface(fn=generateAudio, inputs=[Textbox(label="text_to_audio"), Textbox(label="
|
104 |
+
")], outputs="text")
|
105 |
iface.launch()
|