Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

128 Zeilen
4.8KB

  1. using Services.ReActAgent;
  2. using System.Diagnostics;
  3. using ToolsServices;
  4. namespace Services
  5. {
  6. public static class TranscriptionAndResumeService
  7. {
  8. public static async Task<(bool, string)> TranscribeAudio(string fullFileName)
  9. {
  10. try
  11. {
  12. LoggerService.LogInfo($"TranscriptionAndResumeService.TranscribeAudio");
  13. var bActif = await ReActAgent.ReActAgent.IsWhisperActif();
  14. if (!bActif)
  15. {
  16. var msg = "Le service de transcription Whisper n'est pas actif. Veuillez le démarrer et réessayer.";
  17. LoggerService.LogWarning(msg);
  18. return (false, msg);
  19. }
  20. var _Agent = new ReActAgent.ReActAgent();
  21. var (b, s) = await _Agent.TranscribeAudio(fullFileName);
  22. return (b, s);
  23. }
  24. catch (Exception ex)
  25. {
  26. return (false, ex.Message);
  27. }
  28. }
  29. public static async Task<(bool, string)> ResumeTranscribe(string transcribeText, string contexte)
  30. {
  31. try
  32. {
  33. LoggerService.LogInfo($"TranscriptionAndResumeService.ResumeTranscribe");
  34. var bActif = await ReActAgent.ReActAgent.IsOllamaActif(true);
  35. if (!bActif)
  36. {
  37. var msg = "Le service de résumé Ollama n'est pas actif. Veuillez le démarrer et réessayer.";
  38. LoggerService.LogWarning(msg);
  39. return (false, msg);
  40. }
  41. var _Agent = new ReActAgent.ReActAgent();
  42. /*
  43. var prompt = $"""
  44. Tu es un expert en résumé de texte.
  45. Résume le texte suivant en français de manière claire et concise, en utilisant des phrases complètes.
  46. Il s'agit d'une réunion de travail pour faire le bilan du sprint 03 du projet GIEBOX
  47. Texte à résumer :
  48. {transcribeText}
  49. """;
  50. */
  51. var prompt = PromptService.GetPrompt(PromptService.ePrompt.TranscriptionAndResumeService_Resume, transcribeText, contexte);
  52. var (s, m) = await _Agent.AppelerLLMAsync(ModelsUseCases.TypeUseCase.ResumeDocuments, true, prompt, "Résumé d'une transcription", "", false);
  53. return (true, s);
  54. }
  55. catch (Exception ex)
  56. {
  57. return (false, ex.Message);
  58. }
  59. }
  60. public static bool ConvertVideoToAudio(string inputFile, string outputFile)
  61. {
  62. LoggerService.LogInfo($"TranscriptionAndResumeService.ConvertVideoToAudio");
  63. try
  64. {
  65. if (System.IO.File.Exists(outputFile))
  66. {
  67. try
  68. {
  69. System.IO.File.Delete(outputFile);
  70. }
  71. catch (Exception ex)
  72. {
  73. LoggerService.LogError($"TranscriptionAndResumeService.ConvertVideoToAudio : {ex.Message}");
  74. return false;
  75. }
  76. }
  77. // Mono en 16KHz
  78. //var ffmpegArgs = $"-i \"{inputFile}\" -ac 1 -ar 16000 \"{outputFile}\"";
  79. // Stereo en 44.1KHz
  80. var ffmpegArgs = $"-i \"{inputFile}\" -ac 2 -ar 44000 -c:a pcm_s24le \"{outputFile}\"";
  81. var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ServicesExternes", "ffmpeg", "ffmpeg.exe");
  82. var process = new Process
  83. {
  84. StartInfo = new ProcessStartInfo
  85. {
  86. FileName = path, // ffmpeg.exe n'a pas besoin d'être le PATH (variables environnement)
  87. Arguments = ffmpegArgs,
  88. RedirectStandardOutput = true,
  89. RedirectStandardError = true,
  90. UseShellExecute = false,
  91. CreateNoWindow = true
  92. }
  93. };
  94. process.Start();
  95. string output = process.StandardOutput.ReadToEnd();
  96. string error = process.StandardError.ReadToEnd();
  97. process.WaitForExit();
  98. if (process.ExitCode != 0)
  99. {
  100. LoggerService.LogError($"TranscriptionAndResumeService.ConvertVideoToAudio : {error}");
  101. throw new Exception($"Erreur ffmpeg : {error}");
  102. }
  103. return true;
  104. }
  105. catch (Exception ex)
  106. {
  107. LoggerService.LogError($"TranscriptionAndResumeService.ConvertVideoToAudio : {ex.Message}");
  108. return false;
  109. }
  110. }
  111. }
  112. }