Spaces:
Running
Running
Create transcript.py
Browse files- transcript.py +34 -0
transcript.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import os
|
2 |
+
# from dotenv import load_dotenv
|
3 |
+
from groq import Groq
|
4 |
+
|
5 |
+
# Load environment variables from .env file
|
6 |
+
# load_dotenv()
|
7 |
+
|
8 |
+
# Initialize the Groq client
|
9 |
+
client = Groq(
|
10 |
+
api_key='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',
|
11 |
+
)
|
12 |
+
|
13 |
+
def transcribe_audio(filename):
|
14 |
+
"""Transcribe the audio file and return the transcription text."""
|
15 |
+
# Open the audio file
|
16 |
+
with open(filename, "rb") as file:
|
17 |
+
# Create a transcription of the audio file
|
18 |
+
transcription = client.audio.transcriptions.create(
|
19 |
+
file=(filename, file.read()), # Required audio file
|
20 |
+
model="whisper-large-v3", # Required model to use for transcription
|
21 |
+
prompt="", # Optional
|
22 |
+
response_format="json", # Optional
|
23 |
+
language="en", # Optional
|
24 |
+
temperature=0.0 # Optional
|
25 |
+
)
|
26 |
+
|
27 |
+
# Return the transcription text
|
28 |
+
return transcription.text # Access the 'text' property
|
29 |
+
|
30 |
+
# Example usage (you can remove this part later)
|
31 |
+
if __name__ == "__main__":
|
32 |
+
filename = "/Users/sydneydu/Projects/ConcertBuddy/blankspacetrimmed.mp3"
|
33 |
+
transcription_text = transcribe_audio(filename)
|
34 |
+
print(transcription_text) # Print the extracted text for testing
|