junaid17 commited on
Commit
4f39c13
·
verified ·
1 Parent(s): 91a2882

Delete utils.py

Browse files
Files changed (1) hide show
  1. utils.py +0 -96
utils.py DELETED
@@ -1,96 +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
- }
67
-
68
-
69
- # ==================================================
70
- # 🎧 SPEECH TO TEXT 2
71
- # ==================================================
72
-
73
- async def TTS2(
74
- text: str,
75
- output_dir: str = "tts_outputs",
76
- voice: str = "austin",
77
- model: str = "canopylabs/orpheus-v1-english"
78
- ) -> str:
79
- if not text.strip():
80
- raise ValueError("Text cannot be empty")
81
-
82
- os.makedirs(output_dir, exist_ok=True)
83
-
84
- filename = f"{uuid4().hex}.wav"
85
- output_path = os.path.join(output_dir, filename)
86
-
87
- response = client.audio.speech.create(
88
- model=model,
89
- voice=voice,
90
- input=text,
91
- response_format="wav"
92
- )
93
-
94
- response.stream_to_file(output_path)
95
-
96
- return output_path