Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -18,6 +18,46 @@ def extract_text_from_audio(file_path : str) -> str:
|
|
| 18 |
return text
|
| 19 |
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
class TestAgent:
|
| 22 |
def __init__(self):
|
| 23 |
|
|
|
|
| 18 |
return text
|
| 19 |
|
| 20 |
|
| 21 |
+
@tool
|
| 22 |
+
def extract_text_from_audio(file_path: str) -> str:
|
| 23 |
+
"""
|
| 24 |
+
Extract and return text transcription from an audio file using speech recognition.
|
| 25 |
+
|
| 26 |
+
This tool uses Google's speech recognition API to convert spoken audio content
|
| 27 |
+
into text. It supports various audio formats including WAV, AIFF, and FLAC
|
| 28 |
+
(formats supported by the SpeechRecognition library).
|
| 29 |
+
|
| 30 |
+
Args:
|
| 31 |
+
file_path (str): Path to the audio file to be transcribed. The file should
|
| 32 |
+
be in a format compatible with the SpeechRecognition library.
|
| 33 |
+
|
| 34 |
+
Returns:
|
| 35 |
+
str: The extracted text content from the audio file.
|
| 36 |
+
|
| 37 |
+
Raises:
|
| 38 |
+
Exception : the exception
|
| 39 |
+
|
| 40 |
+
Examples:
|
| 41 |
+
>>> extract_text_from_audio("meeting_recording.wav")
|
| 42 |
+
"Hello team, welcome to our weekly meeting..."
|
| 43 |
+
|
| 44 |
+
>>> extract_text_from_audio("/path/to/audio/interview.mp3")
|
| 45 |
+
"Could you please introduce yourself and your background?"
|
| 46 |
+
"""
|
| 47 |
+
|
| 48 |
+
import speech_recognition as sr
|
| 49 |
+
r = sr.Recognizer()
|
| 50 |
+
try:
|
| 51 |
+
with sr.AudioFile(file_path) as source:
|
| 52 |
+
# listen for the data (load audio to memory)
|
| 53 |
+
audio_data = r.record(source)
|
| 54 |
+
# recognize (convert from speech to text)
|
| 55 |
+
text = r.recognize_google(audio_data)
|
| 56 |
+
return text
|
| 57 |
+
except Exception as e:
|
| 58 |
+
return e
|
| 59 |
+
|
| 60 |
+
|
| 61 |
class TestAgent:
|
| 62 |
def __init__(self):
|
| 63 |
|