MrSimple01 commited on
Commit
8345e12
·
verified ·
1 Parent(s): c2a4899

Delete src/audioProcessing.py

Browse files
Files changed (1) hide show
  1. src/audioProcessing.py +0 -57
src/audioProcessing.py DELETED
@@ -1,57 +0,0 @@
1
- import os
2
- import tempfile
3
- import requests
4
- import json
5
- import uuid
6
- from typing import Tuple, Optional, Dict, Any
7
-
8
- def transcribe_audio(audio_file, api_key, model_id="scribe_v1"):
9
- if not api_key:
10
- return {"error": "Please provide an API key"}
11
- url = "https://api.elevenlabs.io/v1/speech-to-text"
12
- headers = {
13
- "xi-api-key": api_key
14
- }
15
- files = {
16
- "file": open(audio_file, "rb"),
17
- "model_id": (None, model_id)
18
- }
19
- try:
20
- response = requests.post(url, headers=headers, files=files)
21
- response.raise_for_status()
22
- result = response.json()
23
- return result
24
- except requests.exceptions.RequestException as e:
25
- return {"error": f"API request failed: {str(e)}"}
26
- except json.JSONDecodeError:
27
- return {"error": "Failed to parse API response"}
28
- finally:
29
- files["file"].close()
30
-
31
- def save_transcription(transcription):
32
- if "error" in transcription:
33
- return None, transcription["error"]
34
- transcript_filename = f"transcription_{uuid.uuid4().hex[:8]}.txt"
35
- try:
36
- with open(transcript_filename, "w", encoding="utf-8") as f:
37
- f.write(transcription.get('text', 'No text found'))
38
- return transcript_filename, "Transcription saved as text file"
39
- except Exception as e:
40
- return None, f"Error saving transcription: {str(e)}"
41
-
42
- def process_audio_file(audio_file, elevenlabs_api_key, model_id="scribe_v1") -> Tuple[str, str, str]:
43
- if not elevenlabs_api_key:
44
- return None, "ElevenLabs API key is required for transcription", None
45
-
46
- transcription_result = transcribe_audio(audio_file, elevenlabs_api_key, model_id)
47
-
48
- if "error" in transcription_result:
49
- return None, transcription_result["error"], None
50
-
51
- transcript_text = transcription_result.get('text', '')
52
- transcript_path = tempfile.mktemp(suffix='.txt')
53
-
54
- with open(transcript_path, 'w', encoding='utf-8') as transcript_file:
55
- transcript_file.write(transcript_text)
56
-
57
- return transcript_path, f"Transcription completed successfully. Length: {len(transcript_text)} characters.", transcript_text