Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-23-2005, 03:07 AM   #1
LQ Newbie
Registered: Oct 2005
Posts: 5

Rep: Reputation: 0
voice recognition

Hi .....,

The program i got after a search in the google is given below.It can only play back the sound that i dictate.

But i need to modify this program so that it could identify the the word i spells and print it on the screen.How it would be possible please help me......

//Program that can play back the sound that we dictate

#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdio.h>
#include <linux/soundcard.h>

#define LENGTH 3 /* how many seconds of speech to store */
#define RATE 8000 /* the sampling rate */
#define SIZE 8 /* sample size: 8 or 16 bits */
#define CHANNELS 1 /* 1 = mono 2 = stereo */

/* this buffer holds the digitized audio */
unsigned char buf[LENGTH*RATE*SIZE*CHANNELS/8];

int main()
int fd;/* sound device file descriptor */
int arg;/* argument for ioctl calls */
int status; /* return status of system calls */

/* open sound device */
fd = open("/dev/dsp", O_RDWR);
if (fd < 0) {
perror("open of /dev/dsp failed");

/* set sampling parameters */
arg = SIZE; /* sample size */
status = ioctl(fd, SOUND_PCM_WRITE_BITS, &arg);
if (status == -1)
perror("SOUND_PCM_WRITE_BITS ioctl failed");
if (arg != SIZE)
perror("unable to set sample size");

arg = CHANNELS; /* mono or stereo */
status = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &arg);
if (status == -1)
perror("SOUND_PCM_WRITE_CHANNELS ioctl failed");
if (arg != CHANNELS)
perror("unable to set number of channels");

arg = RATE; /* sampling rate */
status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg);
if (status == -1)
perror("SOUND_PCM_WRITE_WRITE ioctl failed");

while (1) { /* loop until Control-C */
printf("Say something:\n");
status = read(fd, buf, sizeof(buf)); /* record some sound */
if (status != sizeof(buf))
perror("read wrong number of bytes");
printf("You said:\n");
status = write(fd, buf, sizeof(buf)); /* play it back */
if (status != sizeof(buf))
perror("wrote wrong number of bytes");
/* wait for playback to complete before recording again */
status = ioctl(fd, SOUND_PCM_SYNC, 0);
if (status == -1)
perror("SOUND_PCM_SYNC ioctl failed");
}//Program ends here

From george
email: <>
Old 10-23-2005, 11:34 PM   #2
Senior Member
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
What you have is a simple voice recorder. It sounds like what you are looking for is voice recognition software, like CMU Sphinx. Be aware that it's not really packaged for end users and can require considerable CPU resources.
Old 10-25-2005, 02:35 PM   #3
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,147

Rep: Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887
what this seems to be is a program used to record from the sound device and immediately echoes it (not the 'echo' command but actually echoes it, ... you know what i mean) to the sound device.

this is prolly some api for voip (interesting).

there would be considerable programming in order to convert this to print speech but it will be buggy (e.g.- i had to yell 'call home' into my phone about 20 times before it registered for voice dial). i assume that most speech recognition software does some type of recording/ compare of some internal database. start with a small dictionary maybe 10 pre-recorded words and program it to 'echo' the correct word to the screen.

does anyone know of an api that can pull metrics on pitch, frequency, and tone?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
There MUST BE voice recognition! CatBreath Linux - Software 5 03-26-2005 11:16 AM
voice recognition pantera Programming 0 10-20-2004 06:17 AM
voice recognition pantera Programming 2 07-03-2004 05:21 AM
Voice recognition softwere Kahless Linux - Software 1 08-04-2003 01:29 AM
voice recognition ferreter Linux - General 0 03-17-2003 06:22 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:29 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration