dtk31564 2013-04-11 18:19
浏览 136
已采纳

如何从PHP运行MATLAB代码进行隔离的口语识别?

As the title indicates, I have MATLAB code for isolated spoken words recognition, and I want to be able to integrate this project with another one made with PHP for some purpose.

I have not used to deal with such problem before. In other words, it's the first time for me when I need to integrate PHP and MATLAB, so I really don't know where to start and how.

I have read a couple of articles, but I couldn't make it valid.

I have PHP 5.4.9, MATLAB R2012A and Windows 7. The MATLAB project files can be seen on GitHub.

  • 写回答

4条回答 默认 最新

  • duanqilupinf67040 2013-04-19 07:59
    关注

    You have a few options here:

    • is MATLAB installed on the server where the PHP application would be deployed (not your current development environment)? If so you can invoke it directly just like any other program (maltab -r "...") using whatever is the equivalent of EXECUTE command in PHP. Here are some resources (make sure to also checkout the linked questions as well):

      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');
      end
      

      Which 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 app.

    • 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:

      The client being your PHP app. 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 docs first, MATLAB toolboxes are very well documented and usually include many examples. Here are a couple more resources specific to MATLAB Compiler products family:

    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)

    HTH

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题