element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
NI LabVIEW Community
  • Products
  • Dev Tools
  • NI LabVIEW Community
  • More
  • Cancel
NI LabVIEW Community
LabVIEW Challenge Blogs Integrating Python Code in Labview for Keyword Recognition
  • Blog
  • LabVIEW Challenge Blogs
  • Forum
  • Documents
  • Quiz
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join NI LabVIEW Community to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: cbohra00627
  • Date Created: 3 Nov 2023 1:49 PM Date Created
  • Views 1189 views
  • Likes 5 likes
  • Comments 1 comment
  • labview 2023
  • pico and labview
  • LAbVIEW challenge
  • labview
Related
Recommended

Integrating Python Code in Labview for Keyword Recognition

cbohra00627
cbohra00627
3 Nov 2023

Introduction:

There are multiple ways to do keyword Recognition in Labview. Earlier I wanted to implement the MFCC algorithm in labview but after searching a bit online, I realized that it will become a complete project on its own and looking at the time constraint, I started looking at other alternatives. I found that we can use Microsoft Speech API or integrate some python code in the VI for Speech Recognition.

In this blog, I will try to implement keyword recognition in labview by integrating python code and using the pocketsphinx python library.

Requirements:

Python & Labview:

First of all we need the python and labview installed on our system. While trying to integrate python code in labview I was facing some error saying "The specified version of python cannot be loaded".

image

After doing some research I found that this error was due to difference in bitness of the two softwares. The Labview community version is available only in 32 bit version. But I had the 64 bit version of python 3.10 installed on my PC.

After installing the 32 bit version of python 3.10 and selecting it in my VI (discussed later in the blog), the issue got resolved.

Pocketsphinx Python library:

The pocketsphinx python library is an open source continuous speech recognition engine. I will be using this library in our project.

pip install pocketsphinx

Running speech recognition in Python:

Now we will try to create a simple single word speech recognition program and run it. It should be able to identify the keywords: 'fast' & 'slow'.

The python code is given below:

def kw_recog():

    #Import LiveSpeech module
	from pocketsphinx import LiveSpeech

    #Providing the keyword list with sensitivity
	speech = LiveSpeech(kws='E:/Python/spch_recog_pocketsphinx/key.list')

	print("Start Speaking")
	for phrase in speech:
		print(phrase.segments(detailed=False))
		kw = phrase.segments(detailed=False)
		
		#Break out of the loop if it detects fast or slow
		if ((kw[0] == 'fast ') or (kw[0] == 'slow ')):
			break


kw_recog()

We are providing the keyword list and sensitivity in the key.list file. The program will only look for words mentioned in the keyword list. The lesser the sensitivity, the more accurate will be the results but we will have to shout louder. The keyword list should be in the below format:

image

The result is as follows:

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Integrating Simple Python Code in Labview:

Now, we will try to integrate a simple python code in labview. I have created a simple add_num function in python to add two numbers in add_number.py file. The code is below:

def add_num(a, b):
	c = a + b
	return c

The python palette is available under Functions->Connectivity->Python.
image

Open Python Session - To open a python session. Python version needs to be provided.

Python Node - Runs a python function. Need to give the path of the python file where function is defined, function name, input parameters and return type (numeric constant in this case).

Close Python Session - To close the python session.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Implementing Keyword Recognition in Labview:

The code for kw_recog() function is given below:

def kw_recog():

    #Import LiveSpeech module
	from pocketsphinx import LiveSpeech

    #Providing the keyword list with sensitivity
	speech = LiveSpeech(kws='E:/Python/spch_recog_pocketsphinx/key.list')

	print("Start Speaking")
	for phrase in speech:
		print(phrase.segments(detailed=False))
		kw = phrase.segments(detailed=False)
		
		#Break out of the loop if it detects fast or slow
		if ((kw[0] == 'fast ') or (kw[0] == 'slow ')):
			return kw[0][0:-1]

The VI:

image

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Conclusion:

Labview Python palette provides an easy way to integrate and run python codes in labview. The program is not 100% accurate. Sometimes it identifies 'fast' as 'slow' & vice versa. Sometimes, I had to speak multiple times and louder for it to be able to recognize the keyword. The inaccuracy might be due to pronunciation & external noise. I think if it is tuned a little bit, it will work better.

Another alternative is to implement my own keyword recognition algorithm in labview which will be tuned to my pronunciation. I will try this in some other project.

  • Sign in to reply
  • DAB
    DAB over 1 year ago

    Interesting idea.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube