badalsahani commited on
Commit
8d3bf05
·
1 Parent(s): 07b1c22

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +10 -8
app/main.py CHANGED
@@ -3,6 +3,8 @@ import subprocess
3
  from tempfile import TemporaryDirectory
4
  from fastapi import FastAPI, UploadFile
5
  from .srt_to_ssml import sub_to_ssml
 
 
6
 
7
 
8
  app = FastAPI()
@@ -14,7 +16,7 @@ async def main():
14
  @app.post("/")
15
  async def main(file: UploadFile):
16
  with TemporaryDirectory(dir=".") as tempdir:
17
- text = ""
18
  audio_file = f'{tempdir}/audio.wav'
19
  srt_file = f'{tempdir}/audio.srt'
20
  ssml_file = f'{tempdir}/ssml.txt'
@@ -23,15 +25,15 @@ async def main(file: UploadFile):
23
  command = ["las", "gen", "-s", audio_file]
24
  subprocess.run(command)
25
  sub_to_ssml(srt_file, ssml_file, "hi-IN", "hi-IN-SwaraNeural", "Female", "en", "hi")
26
- with open(ssml_file, "r") as f:
27
- text = f.read()
28
- return {"subtitle": text}
29
 
30
 
31
  @app.post("/url")
32
  async def url(url: str):
33
  with TemporaryDirectory(dir=".") as tempdir:
34
- text = ""
35
  input_audio = f'{tempdir}/audio.m4a'
36
  audio_file = f'{tempdir}/audio.wav'
37
  srt_file = f'{tempdir}/audio.srt'
@@ -41,9 +43,9 @@ async def url(url: str):
41
  command = ["las", "gen", "-s", audio_file]
42
  subprocess.run(command)
43
  sub_to_ssml(srt_file, ssml_file, "hi-IN", "hi-IN-SwaraNeural", "Female", "en", "hi")
44
- with open(ssml_file, "r") as f:
45
- text = f.read()
46
- return {"subtitle": text}
47
 
48
  def download_audio(link, output):
49
  command = ["yt-dlp", "-f", "ba*[ext=m4a]", "-o", output, link]
 
3
  from tempfile import TemporaryDirectory
4
  from fastapi import FastAPI, UploadFile
5
  from .srt_to_ssml import sub_to_ssml
6
+ from .s3_handler.py import upload_file
7
+ from uuid import uuid4
8
 
9
 
10
  app = FastAPI()
 
16
  @app.post("/")
17
  async def main(file: UploadFile):
18
  with TemporaryDirectory(dir=".") as tempdir:
19
+ id = str(uuid4())
20
  audio_file = f'{tempdir}/audio.wav'
21
  srt_file = f'{tempdir}/audio.srt'
22
  ssml_file = f'{tempdir}/ssml.txt'
 
25
  command = ["las", "gen", "-s", audio_file]
26
  subprocess.run(command)
27
  sub_to_ssml(srt_file, ssml_file, "hi-IN", "hi-IN-SwaraNeural", "Female", "en", "hi")
28
+ srt_url = upload_file(srt_file, "expressapi", "srt", f"{id}.srt")
29
+ ssml_url = upload_file(ssml_file, "expressapi", "ssml", f"{id}.txt")
30
+ return {"id":id, "srt_url":srt_url, "ssml_url": ssml_url}
31
 
32
 
33
  @app.post("/url")
34
  async def url(url: str):
35
  with TemporaryDirectory(dir=".") as tempdir:
36
+ id = str(uuid4())
37
  input_audio = f'{tempdir}/audio.m4a'
38
  audio_file = f'{tempdir}/audio.wav'
39
  srt_file = f'{tempdir}/audio.srt'
 
43
  command = ["las", "gen", "-s", audio_file]
44
  subprocess.run(command)
45
  sub_to_ssml(srt_file, ssml_file, "hi-IN", "hi-IN-SwaraNeural", "Female", "en", "hi")
46
+ srt_url = upload_file(srt_file, "expressapi", "srt", f"{id}.srt")
47
+ ssml_url = upload_file(ssml_file, "expressapi", "ssml", f"{id}.txt")
48
+ return {"id":id, "srt_url":srt_url, "ssml_url": ssml_url}
49
 
50
  def download_audio(link, output):
51
  command = ["yt-dlp", "-f", "ba*[ext=m4a]", "-o", output, link]