sachin commited on
Commit
5964ead
·
1 Parent(s): a559275

update-tansc

Browse files
Files changed (1) hide show
  1. src/server/main.py +20 -11
src/server/main.py CHANGED
@@ -816,17 +816,26 @@ async def speech_to_speech(
816
  try:
817
  encrypted_content = await file.read()
818
  file_content = decrypt_data(encrypted_content, session_key)
819
- files = {"file": (file.filename, file_content, file.content_type)}
820
- external_url = f"{settings.external_api_base_url}/v1/speech_to_speech?language={decrypted_language}"
821
 
822
- response = requests.post(
823
- external_url,
824
- files=files,
825
- headers={"accept": "application/json"},
826
- stream=True,
827
- timeout=60
828
- )
829
- response.raise_for_status()
 
 
 
 
 
 
 
 
 
 
 
830
 
831
  headers = {
832
  "Content-Disposition": f"inline; filename=\"speech.mp3\"",
@@ -835,7 +844,7 @@ async def speech_to_speech(
835
  }
836
 
837
  return StreamingResponse(
838
- response.iter_content(chunk_size=8192),
839
  media_type="audio/mp3",
840
  headers=headers
841
  )
 
816
  try:
817
  encrypted_content = await file.read()
818
  file_content = decrypt_data(encrypted_content, session_key)
 
 
819
 
820
+
821
+
822
+ with tempfile.NamedTemporaryFile(delete=False, suffix=file.filename) as temp_file:
823
+ # Write the decrypted content to the temp file
824
+ #decrypted_content = await file.read() # Assuming decrypted_content is the file content
825
+ temp_file.write(file_content)
826
+ temp_file_path = temp_file.name
827
+
828
+
829
+ response = dwani.ASR.transcribe(file_path=temp_file_path, language=decrypted_language)
830
+
831
+ transcription = response.get("text","")
832
+
833
+ chat_response = dwani.Chat.create(prompt=transcription, src_lang=decrypted_language, tgt_lang=decrypted_language)
834
+
835
+
836
+ response_text = chat_response.get("response", "")
837
+
838
+ response = dwani.Audio.speech(input=response_text, response_format="mp3")
839
 
840
  headers = {
841
  "Content-Disposition": f"inline; filename=\"speech.mp3\"",
 
844
  }
845
 
846
  return StreamingResponse(
847
+ bytes_iterator(response),
848
  media_type="audio/mp3",
849
  headers=headers
850
  )