ow
This commit is contained in:
1 parent
e60118eb53
commit
2e990e687f
38 files changed
+441
-237
No files matched your search
@@ -4,6 +4,7 @@ using CloudBuilder.AI.Gui.Request;
|
||||
using CloudBuilder.AI.Linkup;
|
||||
using CloudBuilder.AI.Policy;
|
||||
using CloudBuilder.AI.SearchCriteria;
|
||||
using CloudBuilder.Core.Request;
|
||||
using CloudBuilder.Core.Service;
|
||||
using CloudBuilder.Gui;
|
||||
using CloudBuilder.Request.AI;
|
||||
@@ -15,10 +16,13 @@ using CloudBuilder.Security.Policy;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using Krypton.Toolkit;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NAudio.Wave;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Security.Permissions;
|
||||
@@ -106,7 +110,7 @@ namespace CloudBuilder.AI.Gui
|
||||
private void InitGridViewPagination()
|
||||
{
|
||||
searchCriteria = new AiChapterSearchCriteria();
|
||||
gridViewPagination.SetLimit(searchCriteria.limit);
|
||||
gridViewPagination.SetLimit(searchCriteria.limit);
|
||||
gridViewPagination.OnPaginationChanged += SearchChapter;
|
||||
}
|
||||
|
||||
@@ -260,7 +264,7 @@ namespace CloudBuilder.AI.Gui
|
||||
guiOperateHelper.EnableControls(false, contentPanel);
|
||||
//查詢有記錄時,修改等控件有效
|
||||
if (aiBookEntity != null)
|
||||
guiOperateHelper.EnableControls(true, bottomPanel, processPanel,gridViewPagination);
|
||||
guiOperateHelper.EnableControls(true, bottomPanel, processPanel, gridViewPagination);
|
||||
else
|
||||
guiOperateHelper.EnableControls(false, bottomPanel, processPanel, gridViewPagination);
|
||||
}
|
||||
@@ -269,7 +273,7 @@ namespace CloudBuilder.AI.Gui
|
||||
savePanel.Visible = true;
|
||||
operationPanel.Visible = false;
|
||||
|
||||
|
||||
|
||||
guiOperateHelper.EnableControls(true, bottomPanel, contentPanel);
|
||||
guiOperateHelper.EnableControls(false, topPanel, processPanel, gridViewPagination);
|
||||
|
||||
@@ -802,5 +806,114 @@ namespace CloudBuilder.AI.Gui
|
||||
ShowMessageBox.ShowError(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void sentenceGv_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (sentenceGv.RowCount <= 0 || sentenceGv.SelectedCells.Count <= 0)
|
||||
{
|
||||
ShowMessageBox.ShowInfo(securityMessagePolicy.ComposeMessage(SecurityMessagePolicy.GUI_WS_RECORD_NOT_FOUND));
|
||||
return;
|
||||
}
|
||||
|
||||
AiSentenceViewEntity sentence = sentenceGv.GetRowData<AiSentenceViewEntity>(sentenceGv.SelectedCells[0].RowIndex);
|
||||
|
||||
using (Stream audioStream = ServiceHelper.GetService<IServiceRequest>()!.PostStreamAsync("/AiBook/GetTtsStream?text=" + sentence.Content, null, string.Empty).GetAwaiter().GetResult())
|
||||
{
|
||||
PlayMp3Stream(audioStream);
|
||||
}
|
||||
}
|
||||
catch (ValidatedException ex)
|
||||
{
|
||||
ShowMessageBox.ShowInfo(ex.Message);
|
||||
}
|
||||
catch (ServiceErrorException ex)
|
||||
{
|
||||
ShowMessageBox.ShowError(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ShowMessageBox.ShowError(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayMp3Stream(Stream audioStream)
|
||||
{
|
||||
string tempFile = Path.Combine(Path.GetTempPath(), "temp_audio.mp3");
|
||||
|
||||
// 保存流到临时文件
|
||||
using (var fs = new FileStream(tempFile, FileMode.Create))
|
||||
{
|
||||
audioStream.Position = 0;
|
||||
audioStream.CopyTo(fs);
|
||||
}
|
||||
|
||||
// 直接调用你已经能播放的方法!!!
|
||||
//PlayAudioFile(tempFile);
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
PlayAudioFile(tempFile); // 后台播放
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(tempFile); // 播完删除
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void PlayAudioFile(string filePath)
|
||||
{
|
||||
// 必用这种写法,绝对不会提前释放
|
||||
var reader = new AudioFileReader(filePath);
|
||||
|
||||
var waveOut = new WaveOutEvent();
|
||||
|
||||
waveOut.Init(reader);
|
||||
waveOut.Play();
|
||||
|
||||
// 同步等待播放完成(这是最稳、最不会出错的)
|
||||
while (waveOut.PlaybackState == NAudio.Wave.PlaybackState.Playing)
|
||||
{
|
||||
System.Threading.Thread.Sleep(100);
|
||||
}
|
||||
|
||||
// 播放完再释放
|
||||
waveOut.Dispose();
|
||||
reader.Dispose();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void DownloadFile(int fileId, string saveFilePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
ServiceHelper.GetService<IServiceRequest>()!.DownloadFile("/DmsFile/DownloadFile?fileId=" + fileId, saveFilePath, null, OpenFile);
|
||||
}
|
||||
catch (ValidatedException ex)
|
||||
{
|
||||
ShowMessageBox.ShowInfo(ex.Message);
|
||||
}
|
||||
catch (ServiceErrorException ex)
|
||||
{
|
||||
ShowMessageBox.ShowError(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ShowMessageBox.ShowError(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenFile(string fileFullName)
|
||||
{
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = fileFullName,
|
||||
UseShellExecute = true // 使用Windows Shell执行
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user