Gravity: Speech Synthesis Module English/Chinese XFS5152 Wiki - DFRobot

Introduction

Would you like to add voice to your projects? Connect up this Speech Synthesis module, add few couples of lines of code, then here goes, your project starts speaking. Both Chinese and English are "so easy" for this speech synthesis module. It also can broadcast the current time and environment data. Combining with a speech recognition module, you can easily have conversations with your projects! The module uses I2C and UART two communication modes, gravity interface, and is compatible with most main-controllers on the market. Besides, the module already comes with a speaker, so you don't need to buy one.

Note: the addresses of the speech synthesis module and micro: bit motor driver board are the same, so they cannot be used together.

Features

Application

Specification

Board Overview

Board Overview

Num Label Description
1 D/T I2C data line/TX
2 C/T I2C clock line/RX
3 GND -
4 VCC +
5 AOP Audio Output Positive
6 AON Audio Output Negative

Tutorial

Requirements

Connection Diagram

Connection

/**
   *  @brief Speech Synthesis function 
   *  @param word Content to be synthesized, it can be Chinese, English, number, etc. 
   */
  void speak(String word);

  /**
   *  @brief Set voice volume 
   *  @param voc, Volume value(0-9)
   */
  void setVolume(uint8_t voc);

  /**
   *  @brief Set playback speed 
   *  @param speed, speed value (0-9)
   */
  void setSpeed(uint8_t speed);

  /**
   *  @brief Set voice type 
   *  @param FEMALE1,     //Female 1, recommended
   *         MALE1,       //Male 1, recommended
   *         MALE2,       //Male 2
   *         FEMALE2,     //Female 2
   *         DONALDDUCK,  //Donald Duck
   *         FEMALE3,     //Female 3
   */
  void setSoundType(eSoundType_t type);

  /**
   *  @brief Set tone 
   *  @param tone, tone value(0-9)
  */
  void setTone(uint8_t tone);

  /**
   *  @brief Set English Pronounce mode 
   *  @param pron(ALPHABET: letter, WORD: word)
   */
  void setEnglishPron(eENpron_t pron);

This speech synthesis module supports multiple text control identifiers that allow users to set voice speaker, volume, speed, and intonation, etc. Identifiers are only used as control flags to realize function setting, and will not be synthesized into sound output. For instance, "[S1]I talk slowly. [S8] I talk fast", after setting the identifiers, the former sentence will be read very slowly while the latter one will be spoken very fast, but "S1" and "S8" will not be read out.

Note: these identifieres are global control identifiers, which means that they only need to be set for once. When the chip is not reset, or powered off, or using [D] to restore the default setting, all texts sent to the chip will be under their control.

Control Identifiers

Sample Code 1- Speech Synthesis via I2C

The module repeatedly reads out the synthesised speech (Dial the switch to I2C).

/*!
 * @file i2c.ino
 * @brief Control speech synthesis sensor via I2C, and synthetise speech 
 * @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @licence     The MIT License (MIT)
 * @author [fengli](li.feng@dfrobot.com)
 * @version  V1.0
 * @date  2020-11-6
 * @get from https://www.dfrobot.com
 * @url https://github.com/DFRobot/DFRobot_SpeechSynthesis
 */
#include "DFRobot_SpeechSynthesis.h"
DFRobot_SpeechSynthesis_I2C ss;
void setup() {
  //Init speech synthesis sensor
  ss.begin();
  //Set voice volume to 5
  //ss.setVolume(5);
  //Set playback speed to 5
  //ss.setSpeed(5);
  //Set speaker to female 
  //ss.setSoundType(ss.FEMALE1);
  //Set tone to 5
  //ss.setTone(5);
  //For English, speak word 
  //ss.setEnglishPron(ss.WORD);
}

void loop() {
  ss.speak(F("She sells seashells by the seashore"));
  ss.speak(F("Hello, I'm Speech Synthesis module"));
  ss.speak(F("a b c d e f g"));

  /*Use text control identifier*/
  //Voice volume identifier 
  //ss.speak(F("[v3]Hello [v8]world"));
  //Word Pronounce mode identifier 
  //ss.speak(F("[h1]Hello [h2]world"));
}

Sample Code 2- Speech Synthesis via UART

The module repeatedly reads out the synthesised speech (Dial the switch to UART). It is recommended to use hardware serial port for stable communication.

/*!
 * @file uart.ino
 * @brief Control speech synthesis sensor via UART, and synthetise speech
 * @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @licence     The MIT License (MIT)
 * @author [fengli](li.feng@dfrobot.com)
 * @version  V1.0
 * @date  2020-11-6
 * @get from https://www.dfrobot.com
 * @url https://github.com/DFRobot/DFRobot_SpeechSynthesis
 */
#include "DFRobot_SpeechSynthesis.h"
#include <SoftwareSerial.h>
SoftwareSerial ssSerial1(2, 3);  //RX, TX
DFRobot_SpeechSynthesis_UART ss;

void setup() {
  ssSerial1.begin(115200);
  //Init speech synthesis sensor
  ss.begin(ssSerial1);

  //Set voice volume to 5
  //ss.setVolume(5);
  //Set playback speed to 5
  //ss.setSpeed(5);
  //Set speaker to female 
  //ss.setSoundType(ss.FEMALE1);
  //Set tone to 5
  //ss.setTone(5);
  //For English, speak word 
  //ss.setEnglishPron(ss.WORD);
}

void loop() {
  ss.speak(F("She sells seashells by the seashore"));
  ss.speak(F("Hello, I'm Speech Synthesis module"));
  ss.speak(F("a b c d e f g"));

  /*Use text control identifier*/
  //Voice volume identifier 
  //ss.speak(F("[v3]Hello [v8]world"));
  //Word Pronounce mode identifier
  //ss.speak(F("[h1]Hello [h2]world"));
}

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents