junaid17 commited on
Commit
2f184e5
·
verified ·
1 Parent(s): 5099d0e

Delete utils.py

Browse files
Files changed (1) hide show
  1. utils.py +0 -66
utils.py DELETED
@@ -1,66 +0,0 @@
1
- import os
2
- from uuid import uuid4
3
- import edge_tts
4
- from groq import Groq
5
- from dotenv import load_dotenv
6
-
7
- load_dotenv()
8
-
9
- client = Groq()
10
-
11
- # ==================================================
12
- # 🎙️ TEXT TO SPEECH (FIXED VOICE)
13
- # ==================================================
14
-
15
- DEFAULT_VOICE = "en-US-MichelleNeural"
16
-
17
- async def TTS(
18
- text: str,
19
- output_dir: str = "tts_outputs",
20
- rate: str = "+0%",
21
- pitch: str = "+0Hz"
22
- ) -> str:
23
-
24
- if not text.strip():
25
- raise ValueError("Empty text")
26
-
27
- os.makedirs(output_dir, exist_ok=True)
28
-
29
- filename = f"{uuid4().hex}.mp3"
30
- output_path = os.path.join(output_dir, filename)
31
-
32
- communicate = edge_tts.Communicate(
33
- text=text,
34
- voice=DEFAULT_VOICE,
35
- rate=rate,
36
- pitch=pitch
37
- )
38
-
39
- await communicate.save(output_path)
40
- return output_path
41
-
42
-
43
- # ==================================================
44
- # 🎧 SPEECH TO TEXT
45
- # ==================================================
46
-
47
- async def STT(audio_file):
48
- os.makedirs("uploads", exist_ok=True)
49
- file_path = f"uploads/{uuid4().hex}.wav"
50
-
51
- with open(file_path, "wb") as f:
52
- f.write(await audio_file.read())
53
-
54
- with open(file_path, "rb") as f:
55
- transcription = client.audio.transcriptions.create(
56
- file=f,
57
- model="whisper-large-v3-turbo",
58
- response_format="verbose_json",
59
- temperature=0.0
60
- )
61
-
62
- return {
63
- "text": transcription.text,
64
- "segments": transcription.segments,
65
- "language": transcription.language
66
- }