Skip to content

Commit 907c891

Browse files
committed
added transcribe functionality in server.py and Program test instance for it
1 parent cc5dd9d commit 907c891

3 files changed

Lines changed: 48 additions & 12 deletions

File tree

PythonRpcServer/server.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
from echo import EchoProvider
1313
from kaltura import KalturaProvider
1414
from mediaprovider import InvalidPlaylistInfoException
15+
from transcribe import transcribe_audio
16+
17+
import json
1518
import hasher
1619
import ffmpeg
1720
# import phrasehinter
@@ -44,12 +47,12 @@ class PythonServerServicer(ct_pb2_grpc.PythonServerServicer):
4447
# Transcribe it into a json string from the transcribe text
4548
# Make it returns a json string
4649
# change name to TranscribeRPC
47-
def CaptionRPC(self, request, context):
48-
#See CaptionRequest
49-
print( f"CaptionRPC({request.logId};{request.refId};{request.filePath};{request.phraseHints};{request.courseHints};{request.outputLanguages})")
50-
kalturaprovider = KalturaProvider()
51-
result = LogWorker(f"CaptionRPC({request.filePath})", lambda: kalturaprovider.getCaptions(request.refId))
52-
return ct_pb2.JsonString(json = result)
50+
# def CaptionRPC(self, request, context):
51+
# #See CaptionRequest
52+
# print( f"CaptionRPC({request.logId};{request.refId};{request.filePath};{request.phraseHints};{request.courseHints};{request.outputLanguages})")
53+
# kalturaprovider = KalturaProvider()
54+
# result = LogWorker(f"CaptionRPC({request.filePath})", lambda: kalturaprovider.getCaptions(request.refId))
55+
# return ct_pb2.JsonString(json = result)
5356

5457

5558

@@ -125,6 +128,23 @@ def ComputeFileHash(self, request, context):
125128
def GetMediaInfoRPC(self, request, context):
126129
result = LogWorker(f"GetMediaInfo({request.filePath})", lambda: ffmpeg.getMediaInfo(request.filePath))
127130
return ct_pb2.JsonString(json = result)
131+
132+
133+
def TranscribeAudioRPC(self, request, context):
134+
print(f"TranscribeAudioRPC({request.logId};{request.filePath})")
135+
try:
136+
logging.info(f"Starting transcription for file: {request.filePath}")
137+
transcription_result = LogWorker(
138+
f"TranscribeAudioRPC({request.filePath})",
139+
lambda: transcribe_audio(request.filePath)
140+
)
141+
logging.info(f"Transcription completed successfully for: {request.filePath}")
142+
return ct_pb2.JsonString(json=json.dumps(transcription_result))
143+
144+
except Exception as e:
145+
context.set_code(grpc.StatusCode.INTERNAL)
146+
context.set_details(f"Transcription failed: {str(e)}")
147+
return ct_pb2.JsonString(json=json.dumps({"error": str(e)}))
128148

129149
def serve():
130150
print("Python RPC Server Starting")

PythonRpcServer/transcribe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
def transcribe_audio(media_filepath):
1010

1111
if media_filepath == 'TEST-transcribe_example_result':
12-
result_json_file = 'transcribe_example_result.json'
12+
result_json_file = 'transcribe_exampleffmp_result.json'
1313
with open(result_json_file, 'r') as json_file:
1414
transcription_result = json.load(json_file)
1515
return transcription_result
@@ -20,7 +20,7 @@ def transcribe_audio(media_filepath):
2020

2121
# Path to the output JSON file that Whisper will generate
2222
json_output_path = f"{media_filepath}.json"
23-
if os.path.exists(media_filepath):
23+
if os.path.exists(json_output_path):
2424
os.remove(json_output_path)
2525

2626
# Command to run Whisper.cpp inside the container using the main executable

TaskEngine/Program.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,37 @@ static void runQueueAwakerForever() {
133133
_logger.LogInformation("Pausing {0} minutes before first periodicCheck", initialPauseInterval);
134134

135135
// Thread.Sleep(initialPauseInterval);
136-
Task.Delay(initialPauseInterval).Wait();
136+
// Task.Delay(initialPauseInterval).Wait();
137137
// Check for new tasks every "timeInterval".
138138
// The periodic check will discover all undone tasks
139139
// TODO/REVIEW: However some tasks also publish the next items
140140
while (true)
141141
{
142+
// try {
143+
// _logger.LogInformation("Periodic Check");
144+
// queueAwakerTask.Publish(new JObject
145+
// {
146+
// { "Type", TaskType.PeriodicCheck.ToString() }
147+
// });
148+
// } catch (Exception e) {
149+
// _logger.LogError(e, "Error in Periodic Check");
150+
// }
151+
142152
try {
143-
_logger.LogInformation("Periodic Check");
153+
var videoId = "ddceb720-a9d6-417d-b5ea-e94c6c0a86c6";
154+
_logger.LogInformation("Transcription Task Initiated");
144155
queueAwakerTask.Publish(new JObject
145156
{
146-
{ "Type", TaskType.PeriodicCheck.ToString() }
157+
{ "Type", TaskType.TranscribeVideo.ToString() },
158+
{ "videoOrMediaId", videoId }
147159
});
160+
161+
_logger.LogInformation("Transcription Task Published Successfully");
148162
} catch (Exception e) {
149-
_logger.LogError(e, "Error in Periodic Check");
163+
_logger.LogError(e, "Error in Transcription Task");
150164
}
165+
166+
151167
// Thread.Sleep(timeInterval);
152168
Task.Delay(timeInterval).Wait();
153169
_logger.LogInformation("Pausing {0} minutes before next periodicCheck", periodicCheck);

0 commit comments

Comments
 (0)