简介
DFR0699 音频录放模块 Pro 是 DFRobot 最新推出的一体式语音交互模块。集成录放音功能为一体,集成按钮可以一键录音,也支持 Grevity I2C 接口由单片机控制录放音。可以储存 10 段 100s 时长音频,支持耳机和扬声器接口输出,内置功放即插即用。让您轻松地为创意项目添加语音提示或声音互动。
技术规格
- 兼容性
开发板 | 兼容 | 不兼容 | 未测试 |
---|---|---|---|
Arduino AVR | ✔ | ||
micro:bit | ✔ | ||
掌控板 | ✔ | ||
Firebeetle-ESP32 | ✔ |
- 录音功能:
- 单段最长100s,最大10段录音保存
- 语音合成:
- 合成 -999999999.999999999 到 999999999.999999999
- 电气性能:
- 工作电压: 3.3-5V
- 物理特性:
- 外形尺寸:
- 固定孔: 4 x M3
- 控制接口: I2C
- I2C 地址: 0x30-0x39 可设置
- 输出接口:
- 3.5mm 耳机口
- PH2.0 扬声器口
接口说明
- 麦克风
录音时请对准此处 - LED 指示灯
- 灭: 当前编号无录音
- 黄: 当前编号有录音
- 红: 正在录音
- 绿: 正在播放
- 红色闪烁: 正在删除
- 数码管
- 选中的录音编号
- 剩余可录音时间(录音时)
- 拨动开关
操作录放音,详细用法见直接使用 - PH2.0 喇叭接口
连接小喇叭,集成功放输出
PH2.0 喇叭口和 3.5mm 耳机口只能连接其中之一,不能同时连接 - I2C 接口
连接主控板,提供供电和通过I2C控制 - 3.5mm 耳机接口
连接耳机或音箱
PH2.0 喇叭口和 3.5mm 耳机口只能连接其中之一,不能同时连接 - 电位器旋钮
调节音量大小
使用教程
接线说明
- 连接 Gravity-4P I2C 接口至主控板 I2C 接口
如果不需要 I2C 控制,可以不接蓝、绿线- 红: 供电正极 3.3-5V
- 黑: 供电负极 GND
- 蓝: I2C SCL
- 绿: I2C SDA
- 连接 3.5mm 耳机孔或 PH2.0 扬声器口,不可同时连接否则无法正常发出声音
直接使用
录放音模块可以方便的通过拨动按钮进行录放音调试操作
录音
- 上下拨动开关,选中可以存入录音的编号
无录音的编号 LED 不亮 - 长按拨动开关,LED变为红色时,录音开始
- 数码管显示的数字 x10 表示剩余可录音时间。
如显示8,表示还可以录80秒左右 - 任意操作拨动开关即停止录音,
播放
- 上下拨动开关,选中有录音的编号
有录音的编号 LED 显示黄色 - 短按拨动开关,LED变为绿色,开始播放
- 任意操作拨动开关,播放停止
删除
- 上下拨动开关,选中有录音的编号
有录音的编号 LED 显示黄色 - 长按拨动开关,LED 灯快速闪烁红色,开始删除
- LED 闪烁结束后删除完成,当前编号可以重新录音
I2C 使用
I2C 地址设置
录放音模块的 I2C 地址默认为 0x30,可以手动在 0x30-0x39 范围内修改
- 断电,按住拨动开关,同时通电
- LED 灯显示为白色表示进入 I2C 地址设置模式
- 数码管显示的数字是 I2C 地址的低位,如:
显示2表示设置地址为 0x32
显示3表示设置地址为 0x33 - 拨动至想要设置的地址,按下拨动开关即保存
I2C 录放音
录音
录音示例代码功能
- 选中 0 号录音
- 删除 0 号录音
- 倒计时 3 秒开始录音
- 录制 20 秒后停止
#include "DFRobot_VoiceRecorder.h"
#define I2C_ADDRESS 0x30 // default I2C address 0x30
DFRobot_VoiceRecorder_I2C voicerecorder(&Wire, I2C_ADDRESS);
void setup()
{
Serial.begin(115200);
while (voicerecorder.begin() != 0) {
Serial.println("i2c device number error!");
delay(1000);
} Serial.println("i2c connect success!");
Serial.println("Delect Voice 0");
voicerecorder.setVoiceNumber(VOICE_NUMBER_0);
Serial.println("Delete Voice");
voicerecorder.deleteVoice();
for (int8_t n = 3; n > 0; n--)
{
Serial.println(n);
delay(1000);
}
Serial.println("Recode Start");
voicerecorder.recordvoiceStart();
for (int8_t n = 20; n > 0; n--)
{
Serial.println(n);
delay(1000);
}
voicerecorder.recordVoiceEnd();
Serial.println("Recode End");
}
void loop()
{
}
播放
录音示例代码功能
- 从0号录音开始循环播放
- 遇到无录音的则跳过
#include "DFRobot_VoiceRecorder.h"
#define I2C_ADDRESS (0x30) //I2C Address
DFRobot_VoiceRecorder_I2C voicerecorder(&Wire, I2C_ADDRESS);
void setup() {
Serial.begin(115200);
while (voicerecorder.begin() != 0)
{
Serial.println("i2c device number error!");
delay(1000);
}
Serial.println("i2c connect success!");
}
void loop() {
for (uint8_t voiceNum = 0; voiceNum < 10; voiceNum++)
{
voicerecorder.setVoiceNumber(voiceNum); //设置编号
Serial.println("setVoiceNumber " + String(voiceNum));
if (VOICE_NONE == voicerecorder.playVoiceStart()) //开始播放,并检查是否为空
{
Serial.println(String(voiceNum) + " is empty"); //若空则直接进入下一编号
delay(3000);
continue;
}
Serial.println("VoiceStart");
while (voicerecorder.getNowState() == VOICE_PLAYING) //显示剩余时间,结束时退出
{
Serial.println("TimeRemaining " + String(voicerecorder.getTimeRemaining()));
delay(1000);
}
delay(3000);
}
}
I2C 语音合成
语音合成分为两种模式
- VOICE_SYNTHESIS_MODE
输入 -123.987
输出 “负一百二十三点九八七”
可用于直接读出传感器数据,测量参数等
该模式有效范围为9位整数,9位小数。若整数超出范围则停止合成,若小数超出范围则截去尾部。 - VOICE_REPLACE_MODE
输入 15071097
输出 “一五零七一零九七”
可用于朗读学号、电话号码等
该模式有效长度32字符,非数字字符自动跳过,超长字符串会报错
VOICE_SYNTHESIS_MODE 示例
读取A0输入值,输出原始值和计算后的电压值
#include "DFRobot_VoiceRecorder.h"
#define I2C_ADDRESS (0x30) //I2C Address
DFRobot_VoiceRecorder_I2C voicerecorder(&Wire, I2C_ADDRESS);
uint16_t AnalogRaw0;
float AnalogVolt0;
void setup()
{
Serial.begin(115200);
while (voicerecorder.begin() != 0)
{
Serial.println("i2c device number error!");
delay(1000);
}
Serial.println("i2c connect success!");
}
void loop()
{
AnalogRaw0 = analogRead(A0);
AnalogVolt0 = 5.0 * AnalogRaw0 / 1024;
Serial.println(String(AnalogRaw0));
voicerecorder.voiceSynthesis(CHINESE_LANGUAGE, String(AnalogRaw0), VOICE_SYNTHESIS_MODE);
while (voicerecorder.getNowState() != VOICE_NONE);
delay(1000);
Serial.println(String(AnalogVolt0, 2));
voicerecorder.voiceSynthesis(CHINESE_LANGUAGE, String(AnalogVolt0, 2), VOICE_SYNTHESIS_MODE);
while (voicerecorder.getNowState() != VOICE_NONE);
delay(3000);
}
VOICE_REPLACE_MODE 示例
朗读斐波那契数列
#include "DFRobot_VoiceRecorder.h"
#define I2C_ADDRESS (0x30) //I2C Address
DFRobot_VoiceRecorder_I2C voicerecorder(&Wire, I2C_ADDRESS);
uint32_t a[3] = {0, 0, 1};
void setup()
{
Serial.begin(115200);
while (voicerecorder.begin() != 0)
{
Serial.println("i2c device number error!");
delay(1000);
}
Serial.println("i2c connect success!");
}
void loop()
{
Serial.println(String(a[2]));
voicerecorder.voiceSynthesis(CHINESE_LANGUAGE, String(a[2]), VOICE_REPLACE_MODE);
a[0] = a[1], a[1] = a[2];
a[2] = a[0] + a[1];
while (voicerecorder.getNowState() != VOICE_NONE);
delay(3000);
}
Mind+ 教程
-
下载及安装软件。下载地址:http://www.mindplus.cc 详细教程:Mind+基础wiki教程-软件下载安装
-
切换到“上传模式”。 详细教程:Mind+基础wiki教程-上传模式编程流程
-
“扩展”中选择“主控板”中的“Arduino Uno”。 详细教程:Mind+基础wiki教程-加载扩展库流程
-
在执行器中加载音频录放模块(1.7.2版本以下可在用户库中搜索加载录放音模块Mind+库)
-
进行编程,示例程序如下图
-
菜单“连接设备”,“上传到设备”
录音程序
自动顺序录音,录满100秒停止
注意:会删除已存在的录音
播放录音
自动顺序播放录音,若无录音则跳过
Arduino C Reference
/**
* @brief initialization parameters for i2c
* @return 0 or 1, 0 is i2c begin success, 1 is i2c begin error
*/
uint8_t begin();
/**
* @brief Set button mode
* @param BUTTON_MODE_ON 0x00
* @param BUTTON_MODE_OFF 0x01
*/
void setButtonMode(uint8_t mode);
/**
* @brief Set light mode
* @param LIGHT_MODE_OFF 0x00
* @param LIGHT_MODE_ON 0x01
*/
void setLightMode(uint8_t mode);
/**
* @brief set voice number
* @param VOICE_NUMBER_0 0x00
* @param VOICE_NUMBER_1 0x01
* @param VOICE_NUMBER_2 0x02
* @param VOICE_NUMBER_3 0x03
* @param VOICE_NUMBER_4 0x04
* @param VOICE_NUMBER_5 0x05
* @param VOICE_NUMBER_6 0x06
* @param VOICE_NUMBER_7 0x07
* @param VOICE_NUMBER_8 0x08
* @param VOICE_NUMBER_9 0x09
* @return state
* VOICE_SYNTHESISING is speech synthesis state
* VOICE_PLAYING is playing state
* VOICE_RECORDING is recording state
* VOICE_NONE is idle condition set number success
*/
uint8_t setVoiceNumber(uint8_t number);
/**
* @brief get i2c device address
* @return i2c device address
*/
uint8_t getI2CAddress();
/**
* @brief get now state
* @return state
* VOICE_SYNTHESISING is speech synthesis state
* VOICE_PLAYING is playing state
* VOICE_RECORDING is recording state
* VOICE_NONE is idle condition
*/
uint8_t getNowState(void);
/**
* @brief get Button Mode
* @return Mode
* BUTTON_MODE_ON 0x00
* BUTTON_MODE_OFF 0x01
*/
uint8_t getButtonMode(void);
/**
* @brief get light Mode
* @return Mode
* LIGHT_MODE_OFF 0x00
* BUTTON_MODE_OFF 0x01
*/
uint8_t getButtonMode(void);
/**
* @brief get voice number
* @return number
* VOICE_NUMBER_0 0x00
* VOICE_NUMBER_1 0x01
* VOICE_NUMBER_2 0x02
* VOICE_NUMBER_3 0x03
* VOICE_NUMBER_4 0x04
* VOICE_NUMBER_5 0x05
* VOICE_NUMBER_6 0x06
* VOICE_NUMBER_7 0x07
* VOICE_NUMBER_8 0x08
* VOICE_NUMBER_9 0x09
*/
uint8_t getVoiceNumber(void);
/**
* @brief get voice state
* @return state 0 is Current position has audio 1 is empty
*/
uint8_t getVoiceState(void);
/**
* @brief get time reamaining
* @return The time range is 0-100
*/
uint8_t getTimeRemaining(void);
/**
* @brief start record
* @return VOICE_SUCCESS is start record ,VOICE_BUSY is repeat recording or playback,VOICE_NONE is Audio already exists, delete and record
*/
uint8_t recordvoiceStart(void);
/**
* @brief start play
* @return VOICE_SUCCESS is start play ,VOICE_BUSY is repeat recording or playback,VOICE_NONE is no songs in the current number
*/
uint8_t playVoiceStart(void);
/**
* @brief delete voice
* @return VOICE_SUCCESS is delete success ,VOICE_BUSY is repeat recording or playback,VOICE_NONE is no songs in the current number
*/
uint8_t deleteVoice(void);
/**
* @brief End of the tape
* @return VOICE_SUCCESS is end success ,VOICE_NONE is no begin record
*/
uint8_t recordVoiceEnd(void);
/**
* @brief End play
* @return VOICE_SUCCESS is end success ,VOICE_NONE is no begin record
*/
uint8_t playVoiceEnd(void);
/**
* @brief speech synthesis
* @param language is CHINESE_LANGUAGE 0x01
* ENGLISH_LANGUAGE 0x02
* @param number range is (999999999 to -999999999)
* @return VOICE_SUCCESS is speech synthesis success
* VOICE_BUSY is recording or playing. Please finish recording or playing first
* VOICE_SYNTHESISING is In speech synthesis
* DATA_ERROR is data error
* MODE_ERROR is mode error
*/
uint8_t voiceSynthesis(uint8_t language ,int64_t number);
/**
* @brief speech synthesis
* @param language is CHINESE_LANGUAGE 0x01
* ENGLISH_LANGUAGE 0x02
* @param string is Input string the scope is determined by the pattern
* @param mode is VOICE_SYNTHESIS_MODE range (999999999.999999999 to -999999999.999999999)
* VOICE_REPLACE_MODE Nine-bit string
* @return VOICE_SUCCESS is speech synthesis success
* VOICE_BUSY is recording or playing. Please finish recording or playing first
* VOICE_SYNTHESISING is In speech synthesis
* DATA_ERROR is data error
* MODE_ERROR is mode error
*/
uint8_t voiceSynthesis(uint8_t language ,String string ,uint8_t mode);