|
12 | 12 | from echo import EchoProvider |
13 | 13 | from kaltura import KalturaProvider |
14 | 14 | from mediaprovider import InvalidPlaylistInfoException |
| 15 | +from transcribe import transcribe_audio |
| 16 | + |
| 17 | +import json |
15 | 18 | import hasher |
16 | 19 | import ffmpeg |
17 | 20 | # import phrasehinter |
@@ -44,12 +47,12 @@ class PythonServerServicer(ct_pb2_grpc.PythonServerServicer): |
44 | 47 | # Transcribe it into a json string from the transcribe text |
45 | 48 | # Make it returns a json string |
46 | 49 | # 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) |
53 | 56 |
|
54 | 57 |
|
55 | 58 |
|
@@ -125,6 +128,23 @@ def ComputeFileHash(self, request, context): |
125 | 128 | def GetMediaInfoRPC(self, request, context): |
126 | 129 | result = LogWorker(f"GetMediaInfo({request.filePath})", lambda: ffmpeg.getMediaInfo(request.filePath)) |
127 | 130 | 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)})) |
128 | 148 |
|
129 | 149 | def serve(): |
130 | 150 | print("Python RPC Server Starting") |
|
0 commit comments