Spaces:
Sleeping
Sleeping
Commit
•
17d79ff
1
Parent(s):
be71186
fix audio file safari
Browse files
app.ipynb
CHANGED
@@ -193,40 +193,40 @@
|
|
193 |
"source": [
|
194 |
"#| export\n",
|
195 |
"def concatenate_mp3(mp3_files):\n",
|
196 |
-
" if len(mp3_files) == 1:\n",
|
197 |
-
"
|
198 |
-
" else:\n",
|
199 |
-
"
|
200 |
-
"
|
201 |
-
"
|
202 |
-
"
|
203 |
-
"
|
204 |
-
"
|
205 |
-
"
|
206 |
"\n",
|
207 |
-
"
|
208 |
-
"
|
209 |
-
"
|
210 |
-
"
|
211 |
-
"
|
212 |
-
"
|
213 |
"\n",
|
214 |
-
"
|
215 |
-
"
|
216 |
-
"
|
217 |
-
"
|
218 |
-
"
|
219 |
"\n",
|
220 |
-
"
|
221 |
-
"
|
222 |
"\n",
|
223 |
-
"
|
224 |
"\n",
|
225 |
-
"
|
226 |
-
"
|
227 |
-
"
|
228 |
-
"
|
229 |
-
"
|
230 |
]
|
231 |
},
|
232 |
{
|
@@ -488,7 +488,7 @@
|
|
488 |
},
|
489 |
{
|
490 |
"cell_type": "code",
|
491 |
-
"execution_count":
|
492 |
"id": "0420310d-930b-4904-8bd4-3458ad8bdbd3",
|
493 |
"metadata": {},
|
494 |
"outputs": [],
|
|
|
193 |
"source": [
|
194 |
"#| export\n",
|
195 |
"def concatenate_mp3(mp3_files):\n",
|
196 |
+
" # if len(mp3_files) == 1:\n",
|
197 |
+
" # return mp3_files[0]\n",
|
198 |
+
" # else:\n",
|
199 |
+
" # Initialize an empty AudioSegment object for concatenation\n",
|
200 |
+
" combined = AudioSegment.empty()\n",
|
201 |
+
" \n",
|
202 |
+
" # Write out audio file responses as individual files for debugging\n",
|
203 |
+
" # for idx, mp3_data in enumerate(mp3_files):\n",
|
204 |
+
" # with open(f'./{idx}.mp3', 'wb') as f:\n",
|
205 |
+
" # f.write(mp3_data)\n",
|
206 |
"\n",
|
207 |
+
" # Loop through the list of mp3 binary data\n",
|
208 |
+
" for mp3_data in mp3_files:\n",
|
209 |
+
" # Convert binary data to an audio segment\n",
|
210 |
+
" audio_segment = AudioSegment.from_file(io.BytesIO(mp3_data), format=\"mp3\")\n",
|
211 |
+
" # Concatenate this segment to the combined segment\n",
|
212 |
+
" combined += audio_segment\n",
|
213 |
"\n",
|
214 |
+
" #### Return Bytes Method\n",
|
215 |
+
" # # Export the combined segment to a new mp3 file\n",
|
216 |
+
" # # Use a BytesIO object to handle this in memory\n",
|
217 |
+
" # combined_mp3 = io.BytesIO()\n",
|
218 |
+
" # combined.export(combined_mp3, format=\"mp3\")\n",
|
219 |
"\n",
|
220 |
+
" # # Seek to the start so it's ready for reading\n",
|
221 |
+
" # combined_mp3.seek(0)\n",
|
222 |
"\n",
|
223 |
+
" # return combined_mp3.getvalue()\n",
|
224 |
"\n",
|
225 |
+
" #### Return Filepath Method\n",
|
226 |
+
" filepath = TEMP_DIR/(str(uuid.uuid4())+'.mp3')\n",
|
227 |
+
" combined.export(filepath, format=\"mp3\")\n",
|
228 |
+
" print('Saving mp3 file to temp directory: ', filepath)\n",
|
229 |
+
" return str(filepath)"
|
230 |
]
|
231 |
},
|
232 |
{
|
|
|
488 |
},
|
489 |
{
|
490 |
"cell_type": "code",
|
491 |
+
"execution_count": 58,
|
492 |
"id": "0420310d-930b-4904-8bd4-3458ad8bdbd3",
|
493 |
"metadata": {},
|
494 |
"outputs": [],
|
app.py
CHANGED
@@ -104,40 +104,40 @@ def split_text(input_text, max_length=4000, lookback=1000):
|
|
104 |
|
105 |
# %% app.ipynb 10
|
106 |
def concatenate_mp3(mp3_files):
|
107 |
-
if len(mp3_files) == 1:
|
108 |
-
|
109 |
-
else:
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
|
142 |
# %% app.ipynb 11
|
143 |
def create_speech_openai(chunk_idx, input, model='tts-1', voice='alloy', speed=1.0, **kwargs):
|
|
|
104 |
|
105 |
# %% app.ipynb 10
|
106 |
def concatenate_mp3(mp3_files):
|
107 |
+
# if len(mp3_files) == 1:
|
108 |
+
# return mp3_files[0]
|
109 |
+
# else:
|
110 |
+
# Initialize an empty AudioSegment object for concatenation
|
111 |
+
combined = AudioSegment.empty()
|
112 |
+
|
113 |
+
# Write out audio file responses as individual files for debugging
|
114 |
+
# for idx, mp3_data in enumerate(mp3_files):
|
115 |
+
# with open(f'./{idx}.mp3', 'wb') as f:
|
116 |
+
# f.write(mp3_data)
|
117 |
+
|
118 |
+
# Loop through the list of mp3 binary data
|
119 |
+
for mp3_data in mp3_files:
|
120 |
+
# Convert binary data to an audio segment
|
121 |
+
audio_segment = AudioSegment.from_file(io.BytesIO(mp3_data), format="mp3")
|
122 |
+
# Concatenate this segment to the combined segment
|
123 |
+
combined += audio_segment
|
124 |
+
|
125 |
+
#### Return Bytes Method
|
126 |
+
# # Export the combined segment to a new mp3 file
|
127 |
+
# # Use a BytesIO object to handle this in memory
|
128 |
+
# combined_mp3 = io.BytesIO()
|
129 |
+
# combined.export(combined_mp3, format="mp3")
|
130 |
+
|
131 |
+
# # Seek to the start so it's ready for reading
|
132 |
+
# combined_mp3.seek(0)
|
133 |
+
|
134 |
+
# return combined_mp3.getvalue()
|
135 |
+
|
136 |
+
#### Return Filepath Method
|
137 |
+
filepath = TEMP_DIR/(str(uuid.uuid4())+'.mp3')
|
138 |
+
combined.export(filepath, format="mp3")
|
139 |
+
print('Saving mp3 file to temp directory: ', filepath)
|
140 |
+
return str(filepath)
|
141 |
|
142 |
# %% app.ipynb 11
|
143 |
def create_speech_openai(chunk_idx, input, model='tts-1', voice='alloy', speed=1.0, **kwargs):
|