Sometimes it is necessary to add low cost audio to your project. While playing a WAV file would produce high quality, sometimes it is necessary to have a low cost way to add audio to your project. Sensors, low cost robots or toys may require a low cost way to add audio to the project. Text To Speech or TTS is one way to provide feedback to users of your embedded device. While there are TTS modules on the market for embedded applications, they are sometimes hard to obtain or expensive. In this example we demonstrate the use of the Software Automatic Mouth (SAM) TTS program with the PIC32MX270F256D microcontroller.

The PIC32 is a powerful microcontroller. The 32-bit MIPS core running at 48 MHz is powerful enough that it can run a lightweight Text to Speech engine rather easily with a small memory footprint.

The Software Automatic Mouth or SAM TTS engine is a small program which comes in at under 39 KB in size which is much less than the 256KB available on the PIC32MX270F256D microcontroller. When complied on the PIC32 it took less than 16% of program memory and less than 6% of data memory.

The phenome is the smallest unit of speech which distinguishes one word from another. The SAM program includes code that converts text into phenomes then converts those phenomes into speech that is output.

The voice is clear and fairly easy to understand.


Connections

The PIC32MX270F256D generates the TTS signal via a PWM output on RB4. This signal is then fed into a PAM8610 Class D audio amplifier module. A CP2104 USB-UART bridge is connected to the PIC32 as well.


C Program

/*
 * File: Main.c
 * Author: Armstrong Subero
 * Processor: PIC32MX270F256D w/Ext OSC @ 4MHz, PLL to 48 MHz, 3.3v
 * Program: 23_TTS
 * Compiler: XC32 (v1.44, MPLAX X v5.05)
 * Program Version: 1.0
 *                             
 * Program Description: This Program Allows PIC32MX270F256D to use the PWM 
 *                      module to perform TTS.
 * 
 * Hardware Description: A PAM8610 is connected to RB4 and a CP4104 USB-UART 
 *                       bridge is connected to RC5.
 * 
 * Change History:
 *
 * Author             Rev     Date          Description
 * Armstrong Subero   1.0     27/11/2018    Initial Release.
 * 
 * Modified From: Inspired by the www.toughdev.com project.
 *                      
 * Created September 27th, 2018, 1:15 PM
 */


/*******************************************************************************
 * Includes and Defines
 ******************************************************************************/
#include "PIC32MX270_STD.h"
#include "delay.h"
#include "uart1.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "sam.h"
#include "reciter.h"
#include "tts.h"

/*******************************************************************************
* Function Name: void initMain(void)
*
* Specification: initializes main
*
*******************************************************************************/
void initMain(void)
{
    // unlock PPS
    systemReg_Unlock();
    CFGCONbits.IOLOCK = 0;

    RPB4Rbits.RPB4R = 0x0005;   //RB4->OC1
    RPC5Rbits.RPC5R = 0x0001;   //RC5->UART1 TX

    // lock PPS
    CFGCONbits.IOLOCK = 1;
    systemReg_Lock();   
}


int main()
{        
    uc_init();
    initMain();
    
    // initialize UART
    UART1_Initialize(); 
    delay_ms(300);
    
    // initialize the TTS module
    initTTS();
        
     while(1)
     {
      // configure printf to use UART1
      __XC_UART = 1; 
      
      // begin speaking
      printf("Begin");
      
      // speak text
      speakText("Hello");
      delay_ms(500);
      speakText("I am SAM");
      delay_ms(500);
      speakText("Would you like to play a gayme?");
      delay_ms(500);
      
      // end speaking
      printf("End");
    }
}

The main program is less than 100 lines of code and the user simply uses the speakText function to convert the text to speech. The PIC32 will say “Hello, I am SAM, would you like to play a game?”.

Results

The video demonstrates the TTS module in action.


Link To Project

You can download the entire project here!

TTS Project

Leave a Reply

Your email address will not be published. Required fields are marked *