File Exchange

image thumbnail

Using MATLAB with Python

version 1.0.4 (32.1 KB) by Sebastian Castro
Files demonstrating MATLAB and Python interoperability

43 Downloads

Updated 07 Nov 2019

From GitHub

View Version History

View license on GitHub

These are the supporting files for the "How to Call Python from MATLAB" (https://youtu.be/LHEZqpvE7D0) and "How to Call MATLAB from Python" (https://youtu.be/OocdPu1Tcrg) videos.

They show examples of speech-to-text recognition and sentiment analysis of the detected text by combining MATLAB and Python functionality.

This example requires MATLAB R2019b or later, as well as Statistics and Machine Toolbox and Text Analytics Toolbox.

You will also need to install Python and the appropriate packages to run this example. The two main ones you will need are as follows; however, you may need to first resolve other unmet dependencies.

pip install speechrecognition pocketsphinx

This example was tested using Python versions 3.6 and 3.7.

Cite As

Sebastian Castro (2021). Using MATLAB with Python (https://github.com/mathworks/matlab-with-python), GitHub. Retrieved .

Comments and Ratings (7)

Tatyana Kim

when the unit starts (Get audio data from the microphone), my voice does not record. want to experiment with this example.
Help...

Yann Debray

@Abdelwahab There are a number of reasons that could give you this error:
https://www.mathworks.com/help/matlab/matlab_external/undefined-variable-py-or-function-py-command.html
- From the very basic: Python is not installed, to MATLAB cannot find it
- To usual PATH issues: Your current directory might not be where your file mySpeechRecognizer.py is located
Test this with py.importlib.import_module('mySpeechRecognizer')
- More annoying (and more likely): An error in mySpeechRecognizer.py causes MATLAB to prompt this message

Abdelwahab Afifi

I got the following error message " Unable to resolve the name py.mySpeechRecognizer.audioToText."

Yann Debray

Mahshid Khoshlessan

@Damoian I am trying to do the same thing for my project, but found no other way!

Sebastian Castro

@Damian -- There is no automatic converter between the languages. You can keep what you've done in Python and call it from MATLAB for the rest of your project like what is shown in this example. Then, either now or at a later time, you can manually port your existing stuff to MATLAB.

Damian Prashad

I have a project I'd like to duplicate from Python in Matlab. Is this something you can help me with?

Thanks,

MATLAB Release Compatibility
Created with R2019b
Compatible with R2019b and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!