save_path
Browse files
App/Generate/database/DescriptAPI.py
CHANGED
@@ -5,7 +5,7 @@ from collections import deque
|
|
5 |
import wave
|
6 |
import uuid
|
7 |
from pydub import AudioSegment
|
8 |
-
|
9 |
|
10 |
import wave
|
11 |
import struct
|
@@ -101,7 +101,7 @@ def concatenate_wav_files(input_files, file_directory):
|
|
101 |
|
102 |
|
103 |
class Speak:
|
104 |
-
def __init__(self, api_url="https://yakova-embedding.hf.space", dir="
|
105 |
self.api_url = api_url
|
106 |
self.dir = dir
|
107 |
|
@@ -143,8 +143,9 @@ class Speak:
|
|
143 |
|
144 |
async def download_file(self, url):
|
145 |
filename = str(uuid.uuid4()) + ".wav"
|
146 |
-
|
147 |
-
|
|
|
148 |
async with aiohttp.ClientSession() as session:
|
149 |
async with session.get(url) as response:
|
150 |
if response.status == 200:
|
@@ -181,16 +182,19 @@ async def process_narrations(narrations):
|
|
181 |
await asyncio.gather(*[process_task() for _ in range(len(tasks))])
|
182 |
concatinated_file = concatenate_wav_files(files, speak.dir)
|
183 |
|
184 |
-
|
185 |
-
duration_in_seconds = int(len(
|
186 |
|
187 |
-
return results,
|
188 |
|
189 |
|
|
|
190 |
# # Example narrations
|
191 |
# narrations = [
|
192 |
-
# "
|
193 |
-
# "
|
|
|
|
|
194 |
# ]
|
195 |
|
196 |
|
|
|
5 |
import wave
|
6 |
import uuid
|
7 |
from pydub import AudioSegment
|
8 |
+
import tempfile
|
9 |
|
10 |
import wave
|
11 |
import struct
|
|
|
101 |
|
102 |
|
103 |
class Speak:
|
104 |
+
def __init__(self, api_url="https://yakova-embedding.hf.space", dir="/tmp"):
|
105 |
self.api_url = api_url
|
106 |
self.dir = dir
|
107 |
|
|
|
143 |
|
144 |
async def download_file(self, url):
|
145 |
filename = str(uuid.uuid4()) + ".wav"
|
146 |
+
temp_dir = tempfile.TemporaryDirectory()
|
147 |
+
# os.makedirs(self.dir, exist_ok=True)
|
148 |
+
save_path = os.path.join(temp_dir.name, filename)
|
149 |
async with aiohttp.ClientSession() as session:
|
150 |
async with session.get(url) as response:
|
151 |
if response.status == 200:
|
|
|
182 |
await asyncio.gather(*[process_task() for _ in range(len(tasks))])
|
183 |
concatinated_file = concatenate_wav_files(files, speak.dir)
|
184 |
|
185 |
+
audio_file = AudioSegment.from_file(concatinated_file, format="wav")
|
186 |
+
duration_in_seconds = int(len(audio_file) / 1000)
|
187 |
|
188 |
+
return results, [concatinated_file, duration_in_seconds]
|
189 |
|
190 |
|
191 |
+
# duration = 0.23529411764705882
|
192 |
# # Example narrations
|
193 |
# narrations = [
|
194 |
+
# "Hello there ",
|
195 |
+
# "Hello there",
|
196 |
+
# "Hello there",
|
197 |
+
# "Hello there [space]",
|
198 |
# ]
|
199 |
|
200 |
|