I have the following very basic TTS code running on my local server
using System.Speech.Synthesis;
...
SpeechSynthesizer reader = new SpeechSynthesizer();
reader.Speak("This is a test");
This code has a dependency on System.Speech for which I have added a Reference in my VS 2015 project.
Works fine but from what I have read and from trying it I know this will not work when the code is hosted on Azure.
I have read several posts on SO querying if it is actually possible to do TTS on azure. Certainly 2 yrs ago it did not appear to be possible. How to get System.Speech on windows azure websites?
All roads seem to lead to the Microsoft Speech API
https://azure.microsoft.com/en-gb/marketplace/partners/speechapis/speechapis/
I have signed up and have gotten my private and sec keys for calling into this API.
However my question is this. How do I actually call the SpeechAPI? What do I have to change in the simple code example above so that this will work when running on azure?
The speech API you referred to at the Azure marketplace is part of an AI Microsoft project called ProjectOxford which offers an array of APIs for computer vision, speech and language.
These are all RESTful APIs, meaning that you will be constructing HTTP requests to send to a hosted online service in the cloud.
The speech-to-text documentation is available here and you can find sample code for various clients on github. Specifically for C# you can see some code in this sample project.
Please note that ProjectOxford is still in preview (Beta). Additional support for using these APIs can be found on the ProjectOxford MSDN forum.
But just to give you an idea of how your program will look like (taken from the above code sample on github):
AccessTokenInfo token;
// Note: Sign up at http://www.projectoxford.ai for the client credentials.
Authentication auth = new Authentication("Your ClientId goes here", "Your Client Secret goes here");
...
token = auth.GetAccessToken();
...
string requestUri = "https://speech.platform.bing.com/synthesize";
var cortana = new Synthesize(new Synthesize.InputOptions()
{
RequestUri = new Uri(requestUri),
// Text to be spoken.
Text = "Hi, how are you doing?",
VoiceType = Gender.Female,
// Refer to the documentation for complete list of supported locales.
Locale = "en-US",
// You can also customize the output voice. Refer to the documentation to view the different
// voices that the TTS service can output.
VoiceName = "Microsoft Server Speech Text to Speech Voice (en-US, ZiraRUS)",
// Service can return audio in different output format.
OutputFormat = AudioOutputFormat.Riff16Khz16BitMonoPcm,
AuthorizationToken = "Bearer " + token.access_token,
});
cortana.OnAudioAvailable += PlayAudio;
cortana.OnError += ErrorHandler;
cortana.Speak(CancellationToken.None).Wait();
Related
Using the guide here https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/voice-video-calling/get-started-teams-interop?pivots=platform-windows
I am able to join a team meeting from my client app.
Now trying to start a 1:1 call with a teams identity on the client, to another teams identity (on teams); I've tried to use the StartCallAsync method (instead of JoinAsync) from https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/voice-video-calling/get-started-with-voice-video-calling-custom-teams-client
This example is in node - I'm using C# and it looks like the most recent beta build of the SDK does NOT have the threadId property exposed.
Here is the JS code
call_ = await call_agent.startCall([{ microsoftTeamsUserId: calleeTeamsUserId.value.trim() }], { videoOptions: videoOptions, threadId: teamsThreadId });
and this link https://learn.microsoft.com/en-us/javascript/api/azure-communication-services/#azure/communication-calling/startcalloptions?view=azure-communication-services-js states that a threaded is required; however, no such threadId exists for c# SDK
The client goes from a connecting state to a disconnected state - the call never rings
Specific code to make the call
StartCallOptions startCallOptions = new StartCallOptions();
ICommunicationIdentifier[] callees = new ICommunicationIdentifier[1]
{
new MicrosoftTeamsUserIdentifier(*****)
};
call_ = await call_agent.StartCallAsync(callees, startCallOptions);
Azure Communication Services have multiple types of Teams interop, which are in different phases of development by today (1/31/2022). Your combination of interop and programming language is currently not supported. Interop scenarios:
Ability of ACS users to join Teams meeting is generally available for all JS, .net, iOS, Android.
Ability of Teams user manage Teams VoIP calls, Teams PSTN calls, and Teams meetings via ACS JavaScript calling SDK is in public preview. Android, iOS, and .net calling SDKs do not support Teams identities.
You can learn more about the support in the following documentation:
https://learn.microsoft.com/en-us/azure/communication-services/concepts/interop/teams-user-calling
I’m looking to add sms notifications to my Blazor server side application. My plan is to create a windows service that runs on a specified frequency; this service will check data in an Azure sql database (the data is inserted via a web api using entity framework) and send sms notifications to users if certain criteria is met.
My question is, what does integrating Twilio into this look like?( I’ve never used Twilio)
Also, how do I setup a console app to run as a service at a specified frequency?
Lastly, what is best practices as far as the console app accessing my database?
what does integrating Twilio into this look like?( I’ve never used Twilio)
Send SMS Messages with a Messaging Service in C#
// Install the C# / .NET helper library from twilio.com/docs/csharp/install
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
class Program
{
static void Main(string[] args)
{
// Find your Account Sid and Token at twilio.com/console
// DANGER! This is insecure. See http://twil.io/secure
const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const string authToken = "your_auth_token";
TwilioClient.Init(accountSid, authToken);
var message = MessageResource.Create(
body: "This is the ship that made the Kessel Run in fourteen parsecs?",
from: new Twilio.Types.PhoneNumber("+15017122661"),
to: new Twilio.Types.PhoneNumber("+15558675310")
);
Console.WriteLine(message.Sid);
}
}
how do I setup a console app to run as a service at a specified
frequency?
The right solution for scheduling simple processes is Windows Task Scheduler.
There are lots of examples about How to create an automated task using Task Scheduler
Lastly, what is best practices as far as the console app accessing my
database?
Nothing especial but connection string.
"ConnectionStrings": {
"Database": "Server=(url);Database=CoreApi;Trusted_Connection=True;"
},
Create connection string
I've seen some examples of how to create storage resources using ARM and C#. I'm assuming that the same is possible for apps. However, I can't find a working example.
Ideally I'd like to have a c#/Web api app that would be able to deploy another app. The process should be fully automated.
Basically, I'd like to create a new instance of the same app with its own configuration - the process would be triggered by a new customer signing up for my SaaS.
Could someone please give some pointers on how to deal with the above?
Thanks.
It seems that you’d like to deploy web application (deployment package) to Azure app service web app programmatically in C# code, you can try to use Kudu Zip API that allows expanding zip files into folders. And the following sample code works fine for me, you can refer to it.
//get username and password from publish profile on Azure portal
var username = "xxxxx";
var password = "xxxxxxxxxxxxxxxxxxxx";
var AppName = "{your_app_name}";
var base64Auth = Convert.ToBase64String(Encoding.Default.GetBytes($"{username}:{password}"));
var file = File.ReadAllBytes(#"C:\Users\xxx\xxx\WebApplication1.zip");
MemoryStream stream = new MemoryStream(file);
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Basic " + base64Auth);
var baseUrl = new Uri($"https://{AppName}.scm.azurewebsites.net/");
var requestURl = baseUrl + "api/zip/site/wwwroot";
var httpContent = new StreamContent(stream);
var response = client.PutAsync(requestURl, httpContent).Result;
}
Besides, you can use Microsoft.Azure.Management.Fluent to manage your Azure app service.
You could grab the Azure Management Libraries for .Net from Github. Support for Azure App Service is in preview as of v1.2. This enables a very intuitive syntax.
var webApp = azure.WebApps.Define(appName)
.WithRegion(Region.USWest)
.WithNewResourceGroup(rgName)
.WithNewFreeAppServicePlan()
.Create();
There are lots of code samples for both Windows and Linux flavours of Azure App Service shown here: https://github.com/Azure/azure-sdk-for-net/tree/Fluent
There are also some worthwhile reading materials on how to handle data in this kind of scenario; various possibilities and design patterns are covered at https://learn.microsoft.com/en-us/azure/sql-database/sql-database-design-patterns-multi-tenancy-saas-applications
I am using Lync Client SDK 2013, to communicate with Skype for Business through a C# program.
However, I cannot find any reference in SDK documentation on how to make a PSTN call using the SDK.
Is this possible at all? A short C# code example would be useful.
You use the "tel:" URI to say want number you want to dial instead of the sip URI. The number you use depends on the dial plan setup of your Lync Server. If you want to avoid dial plan problems, stick with E164 formatted numbers and it will work with any number on any Lync Server anywhere.
Dialing with the Lync Client is the same as with a normal sip uri except you use a tel formatted uri instead:
var participantUri = new List<string> { "tel:+6491234567" };
var automation = LyncClient.GetAutomation();
automation.BeginStartConversation(AutomationModalities.Audio, participantUri, null, ar =>
{
automation.EndStartConversation(ar);
}, null);
Note: there is no error checking and the BeginStartConversation / EndStartConversation calling can be done in many different ways / styles.
I am trying to post an image to the Computer Vision API of Microsoft Cognitive Services. It requires me to upload the image as an url. I have the uploaded image by the user with an URI like http://localhost:9000/content/8a684db8?file=IMG-20160503-WA0002.jpg on my local pc. I tried the obvious but that doesn't work. How to pass the image to their API?
They also mention I can post the image as a raw binary but I am unable to get how to get going.
PS: You can get the subscription keys using the free subscriptions if you want to test it for some other cases.
localhost is 127.0.0.1, e.g. your PC when accessing from your PC. You should pass external IP of your PC in the internet
Well I was able to get a solution. Didn't post my answer sorry.
Microsoft Computer Vision Documentation This shows how to call their API's using the nuget Microsoft.ProjectOxford.Vision.The below code uploads and analyzes a locally stored image to the analyze endpoint of the Computer Vision API service.
using Microsoft.ProjectOxford.Vision;
using Microsoft.ProjectOxford.Vision.Contract;
private async Task<AnalysisResult> UploadAndAnalyzeImage(string imageFilePath)
{
//
// Create Project Oxford Computer Vision API Service client
//
VisionServiceClient VisionServiceClient = new VisionServiceClient(SubscriptionKey);
Log("VisionServiceClient is created");
using (Stream imageFileStream = File.OpenRead(imageFilePath))
{
//
// Analyze the image for all visual features
//
Log("Calling VisionServiceClient.AnalyzeImageAsync()...");
VisualFeature[] visualFeatures = new VisualFeature[] { VisualFeature.Adult, VisualFeature.Categories, VisualFeature.Color, VisualFeature.Description, VisualFeature.Faces, VisualFeature.ImageType, VisualFeature.Tags };
AnalysisResult analysisResult = await VisionServiceClient.AnalyzeImageAsync(imageFileStream, visualFeatures);
return analysisResult;
}
}
On this Git Repository you can see some samples.Here you also get how you can handle client errors and exceptions.