Spaces:
Sleeping
Sleeping
Added deepgram nova whisperAI application API
Browse files
app.py
CHANGED
|
@@ -85,21 +85,11 @@ async def process_audio():
|
|
| 85 |
return jsonify({"error": str(e)}), 500
|
| 86 |
|
| 87 |
|
| 88 |
-
|
| 89 |
-
import os
|
| 90 |
-
import json
|
| 91 |
-
from deepgram.clients import DeepgramClient
|
| 92 |
-
from deepgram.options import PrerecordedOptions
|
| 93 |
-
|
| 94 |
-
# Replace with your actual Deepgram API key
|
| 95 |
-
DEEPGRAM_API_KEY = "your_deepgram_api_key"
|
| 96 |
-
|
| 97 |
-
async def transcribe_audio(video_file_path, wav_file_path):
|
| 98 |
"""
|
| 99 |
Transcribe audio from a video file using Whisper AI (async function).
|
| 100 |
|
| 101 |
Args:
|
| 102 |
-
video_file_path (str): Path to the input video file.
|
| 103 |
wav_file_path (str): Path to save the converted WAV file.
|
| 104 |
|
| 105 |
Returns:
|
|
@@ -110,13 +100,13 @@ async def transcribe_audio(video_file_path, wav_file_path):
|
|
| 110 |
# Initialize Deepgram client
|
| 111 |
deepgram = DeepgramClient(DEEPGRAM_API_KEY)
|
| 112 |
|
| 113 |
-
# Convert video to audio in WAV format using FFmpeg
|
| 114 |
-
print("Converting video to audio (WAV format)...")
|
| 115 |
-
ffmpeg_command = [
|
| 116 |
-
|
| 117 |
-
]
|
| 118 |
-
subprocess.run(ffmpeg_command, check=True)
|
| 119 |
-
print(f"Conversion successful! WAV file saved at: {wav_file_path}")
|
| 120 |
|
| 121 |
# Open the converted WAV file
|
| 122 |
with open(wav_file_path, 'rb') as buffer_data:
|
|
@@ -153,14 +143,14 @@ async def transcribe_audio(video_file_path, wav_file_path):
|
|
| 153 |
return {"status": "error", "message": f"Error extracting transcript: {e}"}
|
| 154 |
|
| 155 |
# Path to the text file
|
| 156 |
-
output_text_file = "deepGramNovaTranscript.txt"
|
| 157 |
|
| 158 |
# Write the transcript to the text file
|
| 159 |
-
with open(output_text_file, "w", encoding="utf-8") as file:
|
| 160 |
-
|
| 161 |
|
| 162 |
print(f"Transcript saved to: {output_text_file}")
|
| 163 |
-
return
|
| 164 |
else:
|
| 165 |
return {"status": "error", "message": "Invalid response from Deepgram."}
|
| 166 |
|
|
|
|
| 85 |
return jsonify({"error": str(e)}), 500
|
| 86 |
|
| 87 |
|
| 88 |
+
async def transcribe_audio(wav_file_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
"""
|
| 90 |
Transcribe audio from a video file using Whisper AI (async function).
|
| 91 |
|
| 92 |
Args:
|
|
|
|
| 93 |
wav_file_path (str): Path to save the converted WAV file.
|
| 94 |
|
| 95 |
Returns:
|
|
|
|
| 100 |
# Initialize Deepgram client
|
| 101 |
deepgram = DeepgramClient(DEEPGRAM_API_KEY)
|
| 102 |
|
| 103 |
+
# # Convert video to audio in WAV format using FFmpeg
|
| 104 |
+
# print("Converting video to audio (WAV format)...")
|
| 105 |
+
# ffmpeg_command = [
|
| 106 |
+
# "ffmpeg", "-i", video_file_path, "-q:a", "0", "-map", "a", wav_file_path
|
| 107 |
+
# ]
|
| 108 |
+
# subprocess.run(ffmpeg_command, check=True)
|
| 109 |
+
# print(f"Conversion successful! WAV file saved at: {wav_file_path}")
|
| 110 |
|
| 111 |
# Open the converted WAV file
|
| 112 |
with open(wav_file_path, 'rb') as buffer_data:
|
|
|
|
| 143 |
return {"status": "error", "message": f"Error extracting transcript: {e}"}
|
| 144 |
|
| 145 |
# Path to the text file
|
| 146 |
+
# output_text_file = "deepGramNovaTranscript.txt"
|
| 147 |
|
| 148 |
# Write the transcript to the text file
|
| 149 |
+
# with open(output_text_file, "w", encoding="utf-8") as file:
|
| 150 |
+
# file.write(transcript)
|
| 151 |
|
| 152 |
print(f"Transcript saved to: {output_text_file}")
|
| 153 |
+
return transcript
|
| 154 |
else:
|
| 155 |
return {"status": "error", "message": "Invalid response from Deepgram."}
|
| 156 |
|