Thread: Why no voice?

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    50

    Why no voice?

    My english is poor,so I beg your pardon.
    My codes are about playing voice,and it doesn't return error,
    but it has no voice,why?
    Look:
    Code:
    #define OUT_BUFFER_SIZE 6000
    void main()  
    {
    
    	HWAVEOUT     hWaveOut ;
    	PWAVEHDR     pWaveHdr ;
    	WAVEFORMATEX waveformat ;
    	PBYTE        pBuffer;
    	
    	waveformat.wFormatTag      = WAVE_FORMAT_PCM ;
    	waveformat.nChannels       = 2 ;
    	waveformat.nSamplesPerSec  = 44100; ;
    	waveformat.nAvgBytesPerSec = 44100*16*2/8 ;
    	waveformat.nBlockAlign     = 16*2/8 ;
    	waveformat.wBitsPerSample  = 16 ;
    	waveformat.cbSize          = 0 ;
    	
    	
    	
    	// open   
    	if (waveOutOpen (&hWaveOut, WAVE_MAPPER, &waveformat,0, 0, 0)!= MMSYSERR_NOERROR)
    	{
    		printf("waveOutOpen error \n");
    		return ;
    	}
    	
        
    	pWaveHdr =(PWAVEHDR)malloc (sizeof (WAVEHDR)) ;
            pBuffer  = (PBYTE)malloc (OUT_BUFFER_SIZE) ;
    	
    	// prepare buffer   
            pWaveHdr->lpData          = (char*)pBuffer ;
    	pWaveHdr->dwBufferLength  = OUT_BUFFER_SIZE ;
    	pWaveHdr->dwBytesRecorded = 0 ;
    	pWaveHdr->dwUser          = 0 ;
    	pWaveHdr->dwFlags         = 0 ;
    	pWaveHdr->dwLoops         = 1 ;
    	pWaveHdr->lpNext          = NULL ;
    	pWaveHdr->reserved        = 0 ;
    	
           if(waveOutPrepareHeader(hWaveOut, pWaveHdr,sizeof (WAVEHDR))!=MMSYSERR_NOERROR) 
    	{
    		printf("waveOutPrepareHeader error \n");
    		return ;
    	}
    	// play   
    	memset(pBuffer,70,OUT_BUFFER_SIZE);
    	if(waveOutWrite (hWaveOut, pWaveHdr, sizeof (WAVEHDR)) !=MMSYSERR_NOERROR) 
    	{
    		printf("waveOutWrite error \n");
    		return ;
    	}
    	
    	// clean   
           if(waveOutReset(hWaveOut) !=MMSYSERR_NOERROR)
    	{
    		printf("waveOutReset error \n");
    		return ;
    	}
    
          if(waveOutUnprepareHeader (hWaveOut, pWaveHdr, sizeof (WAVEHDR)) !=MMSYSERR_NOERROR)
    	{
    		printf("waveOutUnprepareHeader error \n");
    		return ;
    	}
    
           if(waveOutClose(hWaveOut)!=MMSYSERR_NOERROR)
    	{
    		printf("waveOutClose error \n");
    		return ;
    	}
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Pulse-code modulation - Wikipedia, the free encyclopedia
    You get noise, by having changes in the data.

    > memset(pBuffer,70,OUT_BUFFER_SIZE);
    6K of constant values is boring.
    Try filling it with random values, or maybe a chunk of a suitably encoded wav file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Is your "voice" data recorded in a wave file of some kind?

    If so, just use the PlaySound() API.

    If you are trying to generate voice programattically by wave output, you are in for one BIG job... Not only will you need to assemble phonetic samples in several variations, you will need to play those samples in response to text... that is you will need to parse "This is a test" (for example) into it's 8 phonetic components and play them one after the other. Major software houses have worked on this technology for years and are only now getting it so the voice sounds natural enough to not irritate people...

    Microsoft Speech Technologies
    Last edited by CommonTater; 11-24-2011 at 11:36 PM.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Salem View Post
    Pulse-code modulation - Wikipedia, the free encyclopedia
    You get noise, by having changes in the data.

    > memset(pBuffer,70,OUT_BUFFER_SIZE);
    6K of constant values is boring.
    Try filling it with random values, or maybe a chunk of a suitably encoded wav file.
    6000 values at 44100 values per second will give him about 0.13 seconds of sound... the very best he'll get from that is a click from the speaker.

    60,000 random values could produce a buzzing sound for about 1.3 seconds.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Quite - in fact half that time, since the header specifies 16-bit samples.
    And half again, since the header specifies stereo output.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    50
    but I define OUT_BUFFER_SIZE,look:
    #define OUT_BUFFER_SIZE (44100*16*2/8*10)
    it has no voice,too.
    Why?

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by leetow2003 View Post
    but I define OUT_BUFFER_SIZE,look:
    #define OUT_BUFFER_SIZE (44100*16*2/8*10)
    it has no voice,too.
    Why?
    Tell me something... when you opened the wave output... exactly what did you expect to happen?

  8. #8
    Registered User
    Join Date
    Jun 2011
    Posts
    50
    Quote Originally Posted by CommonTater View Post
    Tell me something... when you opened the wave output... exactly what did you expect to happen?
    I want to listen to voice,and when I
    #define OUT_BUFFER_SIZE (44100*16*2/8*10)
    I want to listen for 10 seconds,but I don't listen,
    why?

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Like I said - did you write in any valid PCM data or did you just fill it with a constant again?

    And I think it should be 44100 * 2 * 2 * 10

    That's nSamplesPerSec * nChannels * wBitsPerSample/8 * seconds.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by leetow2003 View Post
    I want to listen to voice,and when I
    #define OUT_BUFFER_SIZE (44100*16*2/8*10)
    I want to listen for 10 seconds,but I don't listen,
    why?
    Ok let me ask my question one more time...

    EXACTLY what did you expect to happen when you opened the waveout?

    Did you expect it to just start talking?
    Last edited by CommonTater; 11-26-2011 at 10:29 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Voice Commands
    By Cody Guhl in forum Windows Programming
    Replies: 1
    Last Post: 05-13-2006, 01:58 PM
  2. voice echo
    By realcr in forum Windows Programming
    Replies: 5
    Last Post: 04-20-2006, 04:31 AM
  3. Get Stream of voice
    By mailyoulike in forum C Programming
    Replies: 2
    Last Post: 04-20-2005, 07:05 AM
  4. encode voice to mp3
    By nihong98 in forum Linux Programming
    Replies: 2
    Last Post: 07-27-2002, 06:13 AM
  5. voice technologies
    By Dissata in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-04-2002, 04:22 AM