|
- using Services.ReActAgent;
- using System.Diagnostics;
- using ToolsServices;
-
- namespace Services
- {
- public static class TranscriptionAndResumeService
- {
- public static async Task<(bool, string)> TranscribeAudio(string fullFileName)
- {
- try
- {
- LoggerService.LogInfo($"TranscriptionAndResumeService.TranscribeAudio");
- var bActif = await ReActAgent.ReActAgent.IsWhisperActif();
- if (!bActif)
- {
- var msg = "Le service de transcription Whisper n'est pas actif. Veuillez le démarrer et réessayer.";
- LoggerService.LogWarning(msg);
- return (false, msg);
- }
- var _Agent = new ReActAgent.ReActAgent();
- var (b, s) = await _Agent.TranscribeAudio(fullFileName);
- return (b, s);
- }
- catch (Exception ex)
- {
- return (false, ex.Message);
- }
- }
-
- public static async Task<(bool, string)> ResumeTranscribe(string transcribeText, string contexte)
- {
- try
- {
- LoggerService.LogInfo($"TranscriptionAndResumeService.ResumeTranscribe");
-
- var bActif = await ReActAgent.ReActAgent.IsOllamaActif(true);
- if (!bActif)
- {
- var msg = "Le service de résumé Ollama n'est pas actif. Veuillez le démarrer et réessayer.";
- LoggerService.LogWarning(msg);
- return (false, msg);
- }
-
- var _Agent = new ReActAgent.ReActAgent();
- /*
- var prompt = $"""
- Tu es un expert en résumé de texte.
- Résume le texte suivant en français de manière claire et concise, en utilisant des phrases complètes.
- Il s'agit d'une réunion de travail pour faire le bilan du sprint 03 du projet GIEBOX
- Texte à résumer :
- {transcribeText}
- """;
- */
- var prompt = PromptService.GetPrompt(PromptService.ePrompt.TranscriptionAndResumeService_Resume, transcribeText, contexte);
-
- var (s, m) = await _Agent.AppelerLLMAsync(ModelsUseCases.TypeUseCase.ResumeDocuments, true, prompt, "Résumé d'une transcription", "", false);
-
- return (true, s);
- }
- catch (Exception ex)
- {
- return (false, ex.Message);
- }
- }
-
- public static bool ConvertVideoToAudio(string inputFile, string outputFile)
- {
- LoggerService.LogInfo($"TranscriptionAndResumeService.ConvertVideoToAudio");
-
- try
- {
- if (System.IO.File.Exists(outputFile))
- {
- try
- {
- System.IO.File.Delete(outputFile);
- }
- catch (Exception ex)
- {
- LoggerService.LogError($"TranscriptionAndResumeService.ConvertVideoToAudio : {ex.Message}");
- return false;
- }
- }
-
- // Mono en 16KHz
- //var ffmpegArgs = $"-i \"{inputFile}\" -ac 1 -ar 16000 \"{outputFile}\"";
-
- // Stereo en 44.1KHz
- var ffmpegArgs = $"-i \"{inputFile}\" -ac 2 -ar 44000 -c:a pcm_s24le \"{outputFile}\"";
- var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ServicesExternes", "ffmpeg", "ffmpeg.exe");
-
- var process = new Process
- {
- StartInfo = new ProcessStartInfo
- {
- FileName = path, // ffmpeg.exe n'a pas besoin d'être le PATH (variables environnement)
- Arguments = ffmpegArgs,
- RedirectStandardOutput = true,
- RedirectStandardError = true,
- UseShellExecute = false,
- CreateNoWindow = true
- }
- };
-
- process.Start();
-
- string output = process.StandardOutput.ReadToEnd();
- string error = process.StandardError.ReadToEnd();
-
- process.WaitForExit();
- if (process.ExitCode != 0)
- {
- LoggerService.LogError($"TranscriptionAndResumeService.ConvertVideoToAudio : {error}");
- throw new Exception($"Erreur ffmpeg : {error}");
-
- }
- return true;
- }
- catch (Exception ex)
- {
- LoggerService.LogError($"TranscriptionAndResumeService.ConvertVideoToAudio : {ex.Message}");
- return false;
- }
- }
- }
- }
|