C#, How to add Pitch to SpeechSynthesizer.SpeakSsml(String) - c#

I use SpeechSynthesizer.SpeakSsml(String).
However not able to build an SSML containing pitch.
So far I could not find any working example online.

MS's Speech Synthesizer isn't built to do singing synthesis, but you can change the pitch characteristics using the <prosody> element:
SpeechSynthesizer.SpeakSsml("<speak version=\"1.0\" xml:lang=\"en\"><prosody pitch=\"x-low\">Hello World</prosody>.<prosody pitch=\"x-high\">Hello World</prosody></speak>");

Related

Get game being streamed from user's activity on Discord

I'm writing a discord bot in .net, and I need to get the name of the game being streamed by a user.
In discord.py, this is possible with https://discordpy.readthedocs.io/en/rewrite/api.html?highlight=guild#discord.Streaming.details.
I'd like to do this in discord.net, but 'Activity', along with Activity cast to Game and StreamingGame, all return the name of the stream (when streaming), not the actual name of the game. (RichGame gives a null reference exception.)
The game being played is visible when viewing a streaming user on Discord, but as far as I could see, not in the API. So how does discord.py get it?
I checked other libraries and it seems discord.py is the only one supporting it.
I tried to read the source code, but I'm not at all well-versed enough in python to understand it.
Example below:
var user = _client.GetGuild(0).GetUser(0);
Console.WriteLine($"Activity - {user.Activity.Name}");
Console.WriteLine($"Type - {user.Activity.Type}");
var Game = user.Activity as Game;
Console.WriteLine($"Game - {Game.Name}");
var StreamingGame = user.Activity as StreamingGame;
Console.WriteLine($"StreamingGame - {StreamingGame.Name}");
Returns:
Type - Streaming
Game - !giveaway ... Fallout 2 war eh das beste...
StreamingGame - !giveaway ... Fallout 2 war eh das beste...
Querying the the twitch API works, but seems excessive, considering it's available in the discord.py library.
Any help would be appreciated, thank you.

How to save response string from web service into a xml file locally in c#

I'm calling to a web service that has .ashx extension and getting string as a response.Now I am trying to save it in a xml file. project execute correctly but it does not save in xml file.
public void savexmlFile()
{
string wbserviceUrl = "https://someurl.ashx";
WebClient clientOne = new WebClient();
string result = clientOne.DownloadString(wbserviceUrl);
XmlDocument cruisexmlDocument = new XmlDocument();
cruisexmlDocument.LoadXml(result);
cruisexmlDocument.Save("D:/brian office projects/Cruise/Cruise/XmlFiles/Cruisedata/cruiseproduts.xml");
}
how can I do that.
this is the result when we enter url directly in brower.
<CruiseData CreationDate="2015-11-11T00:00:03.9702000+00:00">
<CruiseProduct>
<ID>3706</ID>
<Name>MS SUNRISE SERMIRAMIS COLLECTION</Name>
<Description>
<p>Our Selected Nile Cruise <b>MS Sunrise Semiramis</b> <b>Collection Nile Cruise</b> the world’s greatest open air museum, to Aswan. Be enchanted by the fascinating landscape and rich cultural heritage. On our cruiser you will surely experience one of your most memorable vacations.<br><br><b>The Nile is the world's longest river</b> and a luxury cruise on an elegant ship is the most relaxing way to discover the cultural landmarks and archaeological sites of Egypt. Retrace the routes followed by Egypt's pharaohs from Luxor and wonder at the views over Lake Nasser from Aswan's High Dam.<br><b><br>We offer a choice of luxury Nile cruises</b> with various itineraries along the Nile and across Lake Nasser, and are delighted to feature a small selection of the most intimate, elegant and sophisticated vessels. Normal cruise itineraries include embarkation at Luxor, a cruise to Aswan, then disembarkation in Luxor, although some cruises end in Aswan, or can be booked from Aswan. For cruises ending or starting in Aswan, we can easily book travel between Aswan and Luxor.<br><br><b>Nile cruise holidays are an exceptional</b> way to visit some of Egypt’s most famed and most captivating sights. The famed Valley of the Kings contains more than sixty tombs, chambers and halls: the most famous, Tutankhamen, contains a tomb with the mummy in situ, and the Valley of the Queens offers interesting insights into the Egyptian way of life as Queens and royal children were buried in separate valleys. One of the most magnificent monuments is the Temple of Queen Hatshepsut: dedicated to Egypt’s greatest female pharaoh. The Colossi of Memnon which is two huge stone sentinels overlooking the Nile, requires special mention, as does the Temple of Luxor, and the Temple of Karnack with its daily Sound and Light Show.<br><br><b>With Combo Holidays River Nile cruises</b> covering the routes between Luxor and Aswan; the cruise itineraries feature some fantastic stops along the way. At Edfu there’s a very well preserved temple dedicated to Horus - the second largest temple in Egypt. The Aswan High Dam built during the 1960’s to stem annual floods and provide hydroelectricity, boasts good views over Lake Nasser, and the two islands of the Nile offer contrasting attractions; Kitchener's Island boasts the exotic Botanical Gardens and Elephantine Island is home to the Temple of Khnum with its ram mummies on view at the museum.<br><br><b>MS Sunrise Semiramis</b> will take you on a cruise from Luxor, the world’s greatest open air museum, to Aswan. Be enchanted by the fascinating landscape and rich cultural heritage. On our cruiser you will surely experience one of your most memorable vacations.<br><br><b>64 Standard Cabins</b> are waiting to welcome you. All cabins offer an amazing view on the Nile. The finest facilities can be
String, u downloaded from service has a xml format? If not, cruisexmlDocument.LoadXml(result); doesn't take effect, it just loads in memory XML string.
Just download your content read it as string, and write it. You don't need to handle it as XML excplicitly, unless you need to do some verification that it is a valid XML in some way. Other than that, just download it and write it. Make sure you have permissions to write to your path.
var httpClient = new HttpClient();
var result = httpClient.GetAsync("your url").Result;
System.IO.File.WriteAllText(#"C:\yourxml.xml", result.Content.ReadAsStringAsync().Result);

Text To Speech with SAPI: Custom Language

I'm from Greece and I want to make an application which will use SAPI to interact with the user, but I can't find a way to change the language of SAPI from English to Greek.
My OS is by default Greek & English, and I have SAPI SDK installed; the Greek Language is supported by SAPI.
The problem is that SAPI doesn't automatically recognise the language passed to it, and reverts to saying the individual letters one-by-one.
Here is the code I'm using, with English text:
using SpeechLib;
SpVoice voice = new SpVoice();
voice.Speak("Pdf File Successfully Installed", SpeechVoiceSpeakFlags.SVSFlagsAsync);
voice.WaitUntilDone(30000);
This works, but when I pass Greek text to the function (eg "Να ενα κειμενο"), I see the problem occur.
You can set a language by passing SSML to the Speak API, and including the xml:lang attribute.
For example this should work:
SpVoice voice = new SpVoice();
voice.Speak(
"<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='el-GR'>"
+ "Να ενα κειμενο"
+ "</speak>",
SpeechVoiceSpeakFlags.SVSFlagsAsync|SpeechVoiceSpeakFlags.SVSFIsXML);
voice.WaitUntilDone(30000);
You can also switch language mid-speech. The documentation has this example:
<speak version="1.0"
xmlns="http://www.w3.org/2001/10/synthesis"
xml:lang="en-US">
For English, press 1.
<voice xml:lang="fr-FR" gender="female">
Pour le français, appuyez sur 2 </voice>
</speak>
For more, see here:
https://msdn.microsoft.com/en-us/library/jj127898.aspx

Playing Audio in .Net / C#

I'm an experienced MFC programmer of many years, who for the more recent years has been developing commercial apps in Objective C for Mac and iOS - I'm trying to get up to speed with .Net and C# (as I'm soon going to be required to convert one of my commercial apps from Mac to PC).
I've now worked my way through a couple of books and as an exercise to get more familiar with .Net (and C#) I've decided to have a go at converting one of my none commercial apps to .Net as a learning exercise and all is going well (interface is working, data structures all good) but I need to be able to play audio.
My Mac app generates audio from a series of mathematical formula - imagine a wave generator - not quite the same but similar. On the Mac I generate the audio as 16 bit signed raw audio, use Core Audio to setup audio output routing and then get a callback whenever a new buffer of audio is required for the audio routing (so I can generate the audio on the fly).
I need to do the same on the PC. Unfortunately I find MSDN documentation to be a case of "Can't see the wood for the trees" as there is such a vast amount of documentation. I can find classes that will let me load and play mp3/wav etc files, but I need to generate the audio realtime. Can anyone point me in the right direction to find something that will allow me to fill buffers on the fly as it plays them?
Thx
I have used this sample in several projects with good results. It is basically a .Net wrapper for Windows Waveform Audio API using P/Invoke.
Other choices:
NAudio
Sound Player class from .Net framework
I have created a class that can play audio given Stream derivate as an input. So if you are able to pack your sound-generator into the Stream compatible interface, it could be suitable for you.
How I did it - I used unmanaged waveOut* methods from old Windows multimedia API, and handled the playback from there.
Other options - that I am aware of - use waveOut directly, from this: http://windowsmedianet.sourceforge.net/ or write your own DirectShow source filter, but that might be too complicated, since it has to be written in c++.
If you are interested in giving my component a try, I can make it available to you at no charge, since I need it beta tested (I only used it in several of my projects).
EDIT:
Since there are 6 upvotes to the question, I am offering my component free of charge (if you find useful) here: http://dl.dropbox.com/u/10020780/SimpleAudioPlayer.zip
Maybe you can reflect on it :)
I use Audiere to accomplish this and find it works very well.
It's a C++ lib really, but there are a set of bindings available for C#.
For more info, see the question I asked.
You should have a look at FMOD which allows this kind of operation and much more. It is also cross platform which can be interested if you are also working on a mac.
Alvas.Audio has 3 audio players: Player
player.FileName = "123.mp3";
player.Play();
PlayerEx
public static void TestPlayerEx()
{
PlayerEx plex = new PlayerEx();
plex.Done += new PlayerEx.DoneEventHandler(plex_Done);
Mp3Reader mr = new Mp3Reader(File.OpenRead("in.mp3"));
IntPtr format = mr.ReadFormat();
byte[] data = mr.ReadData();
mr.Close();
plex.OpenPlayer(format);
plex.AddData(data);
plex.StartPlay();
}
static void plex_Done(object sender, DoneEventArgs e)
{
if (e.IsEndPlaying)
{
((PlayerEx)sender).ClosePlayer();
}
}
and RecordPlayer
public static void TestRecordPlayer()
{
RecordPlayer rp = new RecordPlayer();
rp.PropertyChanged += new PropertyChangedEventHandler(rp_PropertyChanged);
rp.Open(new Mp3Reader(File.OpenRead("in.mp3")));
rp.Play();
}
static void rp_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case RecordPlayer.StateProperty:
RecordPlayer rp = ((RecordPlayer)sender);
if (rp.State == DeviceState.Stopped)
{
rp.Close();
}
break;
}
}

SpeechSynthesizer .NET control pitch

I'm trying to change the pitch of spoken text via SSML and the .NET SpeechSynthesizer (System.Speech.Synthesis)
SpeechSynthesizer synthesizer = new SpeechSynthesizer();
PromptBuilder builder = new PromptBuilder();
builder.AppendSsml(#"C:\Users\me\Documents\ssml1.xml");
synthesizer.Speak(builder);
The content of the ssml1.xml file is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ssml:speak version="1.0"
xmlns:ssml="http://www.w3.org/2001/10/synthesis"
xml:lang="en-US">
<ssml:sentence>
Your order for <ssml:prosody pitch="+30%" rate="-90%" >8 books</ssml:prosody>
will be shipped tomorrow.
</ssml:sentence>
</ssml:speak>
The rate is recognized: "8 books" is speaken much slower than the rest, but no matter what value is set for "pitch", it makes no difference ! Allowed values can be found here:
http://www.w3.org/TR/speech-synthesis/#S3.2.4
Am I missing something or is changing the pitch just not supported by the Microsoft Speech engine ?
fritz
While the engine SsmlParser used by System.Speech accepts a pitch attribute in the ProcessProsody method, it does not process it.
It only processes the range, rate, volume and duration attributes. It also parses contour but is processed as range (not sure why)...
Edit: if you don't really need to read the text from a SSML xml file, you can create the text programatically.
Instead of
builder.AppendSsml(#"C:\Users\me\Documents\ssml1.xml");
use
builder.Culture = CultureInfo.CreateSpecificCulture("en-US");
builder.StartVoice(builder.Culture);
builder.StartSentence();
builder.AppendText("Your order for ");
builder.StartStyle(new PromptStyle() { Emphasis = PromptEmphasis.Strong, Rate = PromptRate.ExtraSlow });
builder.AppendText("8 books");
builder.EndStyle();
builder.AppendText(" will be shipped tomorrow.");
builder.EndSentence();
builder.EndVoice();

Categories

Resources