Posts: 1,031
Threads: 246
Joined: Jul 2022
04-04-2024, 09:43 AM
(This post was last modified: 04-04-2024, 09:53 AM by Davider.)
The following code can be successfully executed in LINQPad, but after executing it in LA, there is no output or response.
/*/ role exeProgram; nuget Edgettssharp\Edge_tts_sharp; /*/ //.
using Edge_tts_sharp;
script.setup(trayIcon: true, sleepExit: true);
//..
var voice = Edge_tts.GetVoice().FirstOrDefault(i => i.Name == "Microsoft Server Speech Text to Speech Voice (zh-CN, XiaoxiaoNeural)");
Edge_tts.PlayText("hello world", voice);
I've encountered a similar situation before. Can we add a prompt message to the output pane for this scenario?
Posts: 12,073
Threads: 140
Joined: Dec 2002
I guess PlayText is async, ie in other thread. The main should wait. Or, if you can access the playback thread, set its Background property = false.
Posts: 1,031
Threads: 246
Joined: Jul 2022
Here is the source code link. How do I call it as a library in LA?
https://github.com/Entity-Now/Edge_tts_sharp
// Get a PlayerAudio object
static void getPlayer(string msg, eVoice voice)
{
var player = Edge_tts.GetPlayer(msg, voice);
Console.WriteLine("Start playing");
player.PlayAsync();
Thread.Sleep(3000);
Console.WriteLine("Pause playback");
player.Pause();
Thread.Sleep(3000);
Console.WriteLine("Resume playback");
player.PlayAsync();
Thread.Sleep(5000);
player.Stop();
Console.WriteLine("Playback ended");
}
Posts: 54
Threads: 24
Joined: Jun 2023
Not sure if this will help you, but there is an output (in English, sorry - "The Monkey is Hungry!"). This is cobbled together from one of the test programs in the repo. The unused code and comments haven't been cleaned up, apologies.
// script ""
/*/ nuget t2s\Edge_tts_sharp; /*/
// See https://aka.ms/new-console-template for more information
using Edge_tts_sharp;
using Edge_tts_sharp.Model;
string msg = string.Empty;
msg = "The Monkey is Hungry!";
// 获取xiaoxiao语音包
var voice = Edge_tts.GetVoice().FirstOrDefault(i=> i.Name == "Microsoft Server Speech Text to Speech Voice (zh-CN, XiaoxiaoNeural)");
// 文字转语音,并且设置语速
getPlayer(msg, voice);
Edge_tts.PlayText(msg, voice);
// TextToAudio();
// SaveAudio();
// 保存音频
static void SaveAudio()
{
// 获取xiaoxiao语音包
var voice = Edge_tts.GetVoice().FirstOrDefault(i => i.Name == "Microsoft Server Speech Text to Speech Voice (zh-CN, XiaoxiaoNeural)");
Edge_tts.SaveAudio("hello Edge~", voice, 0, "C:\\audio");
}
// 文本转语音
static void TextToAudio()
{
var voice = Edge_tts.GetVoice().First();
Edge_tts.PlayText("hello Edge~", voice);
}
// 自定义接口使用
static void MyFunc(string msg, eVoice voice)
{
Edge_tts.Invoke(msg, voice, 0, libaray =>
{
// 写入自己的操作
// ...
} );
}
// 获取一个PlayerAudio对象
static void getPlayer(string msg, eVoice voice)
{
var player = Edge_tts.GetPlayer(msg, voice);
Console.WriteLine("开始播放");
player.PlayAsync();
Thread.Sleep(3000);
Console.WriteLine("暂停播放");
player.Pause();
Thread.Sleep(3000);
Console.WriteLine("继续播放");
player.PlayAsync();
Thread.Sleep(5000);
player.Stop();
Console.WriteLine("结束播放");
}
Best regards,
burque505
Posts: 1,031
Threads: 246
Joined: Jul 2022
04-04-2024, 09:45 PM
(This post was last modified: 04-04-2024, 11:00 PM by Davider.)
Gintaras burque505
thanks for your help!