Leveraging cloud capabilities from MATLAB
My day job involves using MATLAB analytics at the heart of big, powerful solution stacks both on the Cloud and running on-premise. The beauty of modern MATLAB as a part of the solution stack is that it offers an unparalleled environment to quickly develop and leverage various technologies to build complete solutions.
From an architecture perspective, the unique value proposition that MATLAB offers is that its extensibility-by-design enables me to choose the best-in-class technology products and services to construct my solution.
Why MATLAB?
Let us ask MATLAB that question and exercise the well known function that provides succinct answers to nearly any question.
why % ans = % % 'Some tall and rich system manager knew it was a good idea.'
That funny bit of MATLAB functionality has been around since Cleve's MATLAB many decades ago (atleast as far back as 1987). In our current release (R2017b), the function will return an answer when requested much like the early versions. To replicate the trivial experiment, try typing why at your MATLAB command prompt.
We are now in 2018. We live in the age of the cloud. Conversational interfaces are appearing on many devices powered by cloud based services. It is a wonderful time to be alive when a personal assistant on your phone can tell you the time, give you directions, order your supplies and save you a trip to the grocery store.
MathWorks products have always played a critical role in accelerating the pace of discovery in science and technology. From prototyping signal processing algorithms all the way to embedding the functionality in a final product, the MathWorks tools play a vital role in a product lifecycle from development all the way to production - Cloud based services are no exception.
I have written about exposing MATLAB functionality as a service in the past but in this space, a demo is worth a thousand words, so to illustrate the point and answer the question, let us build our own cloud powered assistant - one that provides succinct answers to everything.
Building a service
As a first step, I will take the *why.m* file and modify it to provide a textual answer and expose it as a service on MATLAB Production Server running on the Amazon Web Services (AWS) public cloud. Go ahead and give it a try by clicking the button below.
With a click of the button, you have exercised MATLAB code running on MATLAB Production Server. While amusing, it does not fully answer the question on why we would consider using MATLAB for this. To answer that, we look at the MATLAB community and realize the fact that millions of MATLAB users don't all speak English, do they? But on the other hand, I don't speak chinese, japanese, spanish, french, german or any of the many languages spoken by our users worldwide.
However, I do have the power of MATLAB at my fingertips and the power of cloud powered cognitive services at my disposal and that should be all I need.
function str = translatedemo() % TRANSLATEDEMO Example to illustrate calling a cloud based webservice. % Call the Microsoft Translation service running on Azure %% Configure the credentials and initialize authKey = "059[REDACTED]c2f"; param.from = "en"; toArray = {"en","ja","es", "zh-Hans", "fr", "de"}; langChoice = ceil(rand(1,1)*6); param.to = toArray{langChoice}; param.text = why; queryParams = matlab.net.QueryParameter(param); % Generate an answer textStr = why; % Get the text from our earlier example and translate it if required if langChoice~=1 translateService = matlab.net.URI('https://api.microsofttranslator.com/v2/Http.svc/Translate', queryParams); %% Translate the output of our text generator % Create a HTTP request type = matlab.net.http.MediaType('application/xml'); authField = matlab.net.http.field.GenericField('Ocp-Apim-Subscription-Key'); authField.Value = authKey; acceptField = matlab.net.http.field.AcceptField(type); translateRequest = matlab.net.http.RequestMessage(matlab.net.http.RequestMethod.GET, [authField, acceptField]); % Send the request and parse the response translateResponse = translateRequest.send(translateService); str = char(translateResponse.Body.Data.getElementsByTagName('string').item(0).getTextContent()); else % There is no need to translate english str = textStr; end
With a few lines of code, I call a translation service from Microsoft running on their Azure Cloud Computing Platform and get a textual translation of my answer. A few more lines of logic allows me to randomize the output language for this demo. We have made our MATLAB code multi-lingual. Go ahead, and try it out - if the results are in a language you don't understand, please try it again as I randomize the outputs.
Speak to me
Cloud powered services offer the capability to drive conversational interfaces. To further illustrate my point, I will use a Text-to-speech (TTS) technology from the same technology stack that powers Alexa. This is a service called Amazon Polly offered by the Amazon Web Services. With another simple API call, I can convert my output into a natural spoken voice in a multitude of languages and genders. Clicking the next button does exactly that (please check your headphone / speakers / system volume first).
MATLAB is your ally on the journey to the cloud
If you were clicking the buttons above, you have leveraged the power of two prominent public cloud services all from within a few lines MATLAB code that is also running on the cloud. MATLAB offers more than just prepackaged algorithms and APIs to do this. It is a platform optimized to enable you to develop and express your own algorithms.
To illustrate that point, answer our "why" question and complete our demo, I will integrate all of these cloud APIs with some audio signal processing. My tool of choice for this is the Audio System Toolbox™ which provides algorithms and tools for the design, simulation, and desktop prototyping of audio processing systems. It enables low-latency signal streaming from and to audio interfaces, interactive parameter tuning, and automatic generation of audio plugins for digital audio workstations. My objective is to make my cloud based system sound a bit more distinctive by adding some reverberation through some simple signal processing. This takes no more than a few lines of MATLAB code. Please give it a try to test it out and see if you can spot the difference:
% Setup a reverberator. reverb = reverberator('PreDelay', 0, 'WetDryMix', 0.8,'SampleRate', 22050); output = reverb(signal);
To conclude, MATLAB makes it simple to integrate the best-in-class algorithm designs with the variety of services to build full solutions. The demonstration polyglot talking bot operates right from within our blog post and illustrates a trivial example of building a cloud based voice powered service that provides an answer to nearly everything, tuned with some reverberation to sound the way we want it to.
The same principles permit me to build powerful real-world applications that harness the power of MATLAB signal/video processing as well as analytics in real-world industrial, IoT, automotive, aerospace, financial applications.
The takeaway that I am trying to articulate here is that if your journey is headed to the cloud, MATLAB is your trusted friend and ally with technology and powerful time-tested workflows to support it.
P.S: I shall probably be turning off this demo in a few weeks to save operational cost.
- カテゴリ:
- Cloud,
- Deployment
コメント
コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。