How can I run MATLAB code for isolated spoken words recognition from PHP?
You have a few options here:
If MATLAB installed on the server where the PHP application would be deployed (not your current development environment), you can invoke it directly just like any other program (
matlab -r "..."
) using whatever is the equivalent ofEXECUTE
command in PHP. Here are some resources (make sure to also checkout the linked questions as well):- How to call MATLAB from command-line and print to stdout before exiting
- Running a cmd file without GUI popping up
- Pass Parameters _ Shell Script - Octave Script
Others have commented on how to pass input/output between PHP and your MATLAB script. For example, you could design your MATLAB function to receive the path of WAV file as input, process it and save any resulting image to disk:
function myFunc(filename)
[y,Fs] = audioread(filename);
img = my_process_func(y, FS);
imwrite(img, 'out.png');
endWhich is invoked from PHP as:
% Of course you have to make sure "myFunc" is available on the MATLAB path.
% Think: "addpath(..)" or just "cd(..)" into the directory first
matlab -wait -nodisplay -r "myFunc('audio.wav'); quit;"You could then read the output image in the PHP application.
If not, what deployment-related toolboxes do you have available? MATLAB Compiler and related toolboxes like MATLAB Builder NE and MATLAB Builder JA.
Those will compile your program into an executable/.NET Assembly/JAR file respectively, and all of them require the freely available MCR Runtime to be installed. In other words, the executables do not need to have a full MATLAB installation on the target machine, only the MCR runtime.
You would run the executable in the same manner as before.
Another product is the MATLAB Coder, which converts your MATLAB code into C++ program. When compiled, it can run without any external requirement.
A new product by MathWorks is MATLAB Production Server. Personally I know nothing about it :)
Yet another option is to use TCP/IP to communicate between PHP and MATLAB. A server would be run on the MATLAB side, using socket programming written as C MEX-file or a Java class. See:
- MATLAB Mex Socket Wrapper Library
- Writing Java's pw.println(), etc. in MATLAB
The client being your PHP application. The idea is to have MATLAB listening for connections, reading whatever input is given by a client,
eval
it, and return the result. This is more involved than the other options, as you have to deal with serialization and other things like concurrency. The advantage is that MATLAB can be run on a separate server, even on multiple servers on the cloud (see this post).
So first, decide what approach best suits your project, then it would be easier to answer specific questions... Just always consult the documentation first, MATLAB toolboxes are very well documented and usually include many examples. Here are a couple more resources specific to MATLAB Compiler products family:
- Webinar: Application Deployment with MATLAB
- PDF File: MATLAB Application Deployment - Web Example Guide
Note that they concentrate on ASP.NET and Java JSP/servlet applications. In your case, the PHP application would communicate with a middle tier running a web service built using one of the above two options (or simply design a CGI-like site running plain executables built using the MATLAB Compiler as explained earlier).
Calling MATLAB functions from python
PyMat looks like it's been abandoned.
I'm assuming you are on windows so you could always do the simplest approach and use Matlab's COM interface:
>>> import win32com.client
>>> h = win32com.client.Dispatch('matlab.application')
>>> h.Execute ("plot([0 18], [7 23])")
>>> h.Execute ("1+1")
u'\nans =\n\n 2\n\n'
More info here
Related Topics
Laravel 5 Socialite - Curl Error 77: Error Setting Certificate Verify Locations
How to Send an Email Using PHP at Windows Azure
Detect Mobile Devices - and Tablet Devices
Sending Bcc Emails Using a Smtp Server
Aescrypt Decryption Between iOS and PHP
Best Way to Delete "Column" from Multidimensional Array
What's the Best Way to Localise a Date on Laravel
Phpexcel Download Using Ajax Call
How to Convert Utc Datetime to Another Timezone
Soft Delete Best Practices (Php/Mysql)
Include PHP File into HTML File
How to Use PHP In_Array with Associative Array
Recreate Original PHP Array from Print_R Output
How to Replace the Deprecated Set_Magic_Quotes_Runtime in PHP
Is This the Most Efficient Way to Get and Remove First Line in File