📄 voice.c
字号:
VoiceSendData(0x001a);
break;
}
VoiceSendData(GBKToUnicode(((*Text) << 8) | *(Text + 1)));
Text += 2;
}
VOICE_SS_HIGH;
while (1) {
VoiceReadStatus();
if (!(VoiceStatus & WTS_CNVT))
break;
}
// psprintf(LineBuffer, "VOICE:%04x-%04x", VoiceStatus, VoiceData);
// MenuPrintMessage(2);
VoiceSendCommand(WTS_IDLE);
#endif
#ifdef SUPPORT_ENGLISH_VOICE
UINT16 Data;
while (1) {
if (*Text == 0x00) {
VOICE_FIFO_FI(0x1a1a);
break;
}
else {
Data = (*Text) << 8;
Text++;
if (*Text == 0x00) {
Data |= 0x1a;
VOICE_FIFO_FI(Data);
break;
}
else {
Data |= *Text;
VOICE_FIFO_FI(Data);
Text++;
}
}
}
#else
// BYTE *TextShow = Text;
while (1) {
if (*Text == 0x00) {
VOICE_FIFO_FI(0x001a);
break;
}
else if (*Text < 0x80) {
VOICE_FIFO_FI((*Text) << 8);
Text++;
}
else {
VOICE_FIFO_FI(GBKToUnicode(((*Text) << 8) | *(Text + 1)));
Text += 2;
}
}
// ShowDebugStr(TextShow, 0);
#endif
}
void VoiceVolumeUp()
{
if (VoiceVolumeLevel < VOICE_VOLUME_MAX) {
VoiceVolumeLevel++;
VoiceVolume++;
PollingVoice();
#ifdef SUPPORT_ENGLISH_VOICE
VoiceSendQuene("Volume up", VOICE_LEVEL_HI);
#else
VoiceSendQuene("音量加", VOICE_LEVEL_HI);
#endif
#ifdef SUPPORT_I2C_DEVICE
VoiceByteSaveEEP(EEP_POS_USER_VOL, VoiceVolumeLevel);
#endif
}
}
void VoiceVolumeDown()
{
if (VoiceVolumeLevel) {
VoiceVolumeLevel--;
VoiceVolume--;
PollingVoice();
#ifdef SUPPORT_ENGLISH_VOICE
VoiceSendQuene("Volume down", VOICE_LEVEL_HI);
#else
VoiceSendQuene("音量减", VOICE_LEVEL_HI);
#endif
#ifdef SUPPORT_I2C_DEVICE
VoiceByteSaveEEP(EEP_POS_USER_VOL, VoiceVolumeLevel);
#endif
}
}
#define POLYPHONE_TABLE_SIZE (sizeof(PolyphoneTable) / 2 / 5)
const BYTE PolyphoneTable[][2][5] = {
{ "银行", "银航" },
{ "陂", "杯" },
{ "一", "衣" },
};
void VoicePolyphone(BYTE *Text)
{
BYTE *Addr;
BYTE i;
// ShowDebugStr(Text, 0);
for (i = 0; i < POLYPHONE_TABLE_SIZE; i++) {
if ((Addr = strstr(Text, (BYTE *)PolyphoneTable[i][0])) != NULL) {
memcpy(Addr, (BYTE *)PolyphoneTable[i][1], strlen((BYTE *)PolyphoneTable[i][0]));
}
}
// ShowDebugStr(Text, 1);
}
void PollingVoice()
{
if (!VoicePowerUpFlag)
return;
#ifdef SUPPORT_GSM_GUARD
if (TestDSAOK == COMM_INIT_GUARD)
return;
#endif
switch (VoiceState) {
case VOICE_IDLE:
if (VOICE_FIFO_EMPTY) {
PollingVoiceQuene();
if (VoiceVolume) {
VOICE_SS_LOW;
if (VoiceVolume > 0) {
VoiceSendData(WTS_VLUP);
VoiceVolume--;
}
else {
VoiceSendData(WTS_VLDN);
VoiceVolume++;
}
VOICE_SS_HIGH;
}
break;
}
if (CheckSystemState(SYSTEM_NAVIGATION)) {
if ((SwitchSelectState & SW_AUDIO_MASK) != SW_AUDIO_VOICE) {
VoiceSwitchTimer = 100;
SwitchSelect(SW_VIDEO_VCD | SW_AUDIO_VOICE);
break;
}
if (VoiceSwitchTimer)
break;
#if TMBOARD_VERSION >= 2
VOICE_MUTE_OFF;
#endif
}
VoiceReadStatus();
if ((VoiceStatus & WTS_RDY) && (VoiceStatus & WTS_BEMP)) {
VOICE_SS_LOW;
VoiceSendData(WTS_CONV);
#ifndef SUPPORT_ENGLISH_VOICE
VoiceSendData(0xfffe);
#endif
VoiceState = VOICE_CONV;
}
break;
case VOICE_CONV:
if (VOICE_FIFO_EMPTY)
break;
VOICE_FIFO_FO(VoiceData);
VoiceSendData(VoiceData);
#ifdef SUPPORT_ENGLISH_VOICE
if ((VoiceData & 0xff) == 0x001a) {
#else
if (VoiceData == 0x001a) {
#endif
VOICE_SS_HIGH;
VoiceState = VOICE_CONV_DONE;
}
// ShowDebugHex(VoiceFI, 2);
// ShowDebugHex(VoiceFO, 3);
break;
case VOICE_CONV_DONE:
VoiceReadStatus();
if (!(VoiceStatus & WTS_CNVT)) {
VoiceSendCommand(WTS_IDLE);
VoiceState = VOICE_IDLE;
if (CheckSystemState(SYSTEM_NAVIGATION) && VOICE_FIFO_EMPTY &&
VoiceQueneTotal == 0) {
if (FlagMuteOn) SwitchSelect(SW_VIDEO_VCD | SW_AUDIO_CD);
else SwitchSelect(SW_VIDEO_VCD | SW_AUDIO_MUTE);
}
VoiceSwitchTimer = 25;
#if TMBOARD_VERSION >= 2
VOICE_MUTE_ON;
#endif
}
/*
psprintf(LineBuffer, "VOICE:%04x-%04x", VoiceStatus, VoiceData);
MenuPrintMessage(1);
*/
break;
}
}
BYTE VoiceIdle()
{
return (VoicePowerUpFlag && (VoiceState == VOICE_IDLE));
}
void VoiceCancel()
{
VoiceFI = 0;
VoiceFO = 0;
/*
psprintf(LineBuffer, "Voice Cancel : %02x", VoiceState);
MenuPrintMessage(OSD_STATUS_REGION);
*/
if (VoiceState != VOICE_IDLE) {
if (VoiceState == VOICE_CONV) {
VoiceSendData(0x001a);
VOICE_SS_HIGH;
}
VoiceSendData(WTS_IDLE);
VoiceState = VOICE_IDLE;
}
InitVoiceQuene();
}
void VoiceSwitchDelay()
{
VoiceSwitchTimer = 55;
}
BYTE VoiceSelfTest()
{
VoiceReadVersion();
#ifdef MONITOR_HARDWARE_TEST
MenuScreenIndex = 0;
psprintf(LineBuffer, "Test VOICE Version %04x", VoiceData);
#ifdef SUPPORT_FLASH_SERIAL
#ifdef MONITOR_FLASH_TEST
MenuPrintString(2, 5, LineBuffer);
#else
MenuPrintString(2, 3, LineBuffer);
#endif
#else
MenuPrintString(2, 2, LineBuffer);
#endif
#endif
return (VoiceData == 0x0247 ||
VoiceData == 0x0229 ||
#ifdef SUPPORT_ENGLISH_VOICE
VoiceData == 0x0248 ||
#endif
VoiceData == 0x022A);
}
#endif SUPPORT_WINBOND_VOICE
#ifdef SUPPORT_VOICE
void InitVoiceQuene()
{
VoiceQueneTotal = 0;
VoiceQuenePoint = 0;
}
void VoiceSendQuene(BYTE *Text, BYTE Level)
{
UINT16 Offset;
UINT16 Length;
UINT16 Index;
UINT16 i;
if (Level > VOICE_LEVEL_LO) return;
if (Level == VOICE_LEVEL_LO && VoiceQueneTotal) return;
if (VoiceQueneTotal >= VOICE_INDEX_SIZE) return;
if (Text[0] == 0) return;
if ((Length = strlen(Text) + 1) > 200) return;
Offset = VoiceQuenePoint;
for (Index = 0; Index < VoiceQueneTotal; Index++) {
if (Level < VoiceIndexBuffer[Index].Level) {
for (i = Index; i < VoiceQueneTotal; i++) {
if (VoiceIndexBuffer[i].Level == VOICE_LEVEL_LO /* && Length > 10 */)
VoiceQueneTotal--;
}
for (i = Index; i < VoiceQueneTotal; i++) {
VoiceIndexBuffer[VoiceQueneTotal - i] = VoiceIndexBuffer[VoiceQueneTotal - i - 1];
}
break;
}
}
VoiceIndexBuffer[Index].Level = Level;
VoiceIndexBuffer[Index].Offset = Offset;
VoiceIndexBuffer[Index].Length = Length;
for (i = 0; i < Length; i++) {
VoiceQueneBuffer[(Offset + i) & VOICE_QUENE_MASK] = Text[i];
}
VoiceQueneTotal++;
VoiceQuenePoint = (Offset + Length) & VOICE_QUENE_MASK;
#if 0
ShowDebugHex(VoiceQueneTotalVoice, 4);
ShowDebugHex(VoiceQuenePointVoice, 5);
// ShowDebugHex(VoiceIndexBuffer[Index].Offset, 6);
// ShowDebugHex(VoiceIndexBuffer[Index].Length, 7);
#endif
}
void PollingVoiceQuene()
{
UINT16 Offset;
UINT16 Length;
UINT16 i;
if (!VoiceQueneTotal) return;
Offset = VoiceIndexBuffer[0].Offset;
Length = VoiceIndexBuffer[0].Length;
for (i = 0; i < Length; i++) {
VoiceMultiBuffer[i] = VoiceQueneBuffer[(Offset + i) & VOICE_QUENE_MASK];
}
#ifdef SUPPORT_WINBOND_VOICE
VoicePolyphone(VoiceMultiBuffer);
#endif
VoiceSend(VoiceMultiBuffer);
for (i = 1; i < VoiceQueneTotal; i++) {
VoiceIndexBuffer[i - 1] = VoiceIndexBuffer[i];
}
VoiceQueneTotal--;
#if 0
ShowDebugHex(VoiceQueneTotal, 12);
ShowDebugHex(VoiceQuenePoint, 13);
#endif
}
void VoiceTimer10mS()
{
#ifdef SUPPORT_UART_VOICE
if (VoiceVolumeTimer) {
VoiceVolumeTimer--;
if (VoiceVolumeTimer == 0) {
VoiceVolumeStop();
}
}
#endif
#ifdef SUPPORT_WINBOND_VOICE
if (VoiceSwitchTimer) VoiceSwitchTimer--;
#endif
}
#ifdef SUPPORT_I2C_DEVICE
void VoiceInitLoadEEP()
{
I2CRead24C02Array(EEP_ADR_USER_0, DBusEMapBuffer + EEP_ADR_USER_0, EEP_LEN_USER_0);
if (DBusEMapBuffer[EEP_POS_USER_ID5] != EEP_VAL_ID5 ||
DBusEMapBuffer[EEP_POS_USER_VOL] != DBusEMapBuffer[EEP_POS_USER_SUM] ||
DBusEMapBuffer[EEP_POS_USER_VOL] > VOICE_VOLUME_MAX) {
VoiceInitSaveEEP();
}
VoiceVolumeLevel = DBusEMapBuffer[EEP_POS_USER_VOL];
}
void VoiceInitSaveEEP()
{
DBusEMapBuffer[EEP_POS_USER_ID5] = EEP_VAL_ID5;
DBusEMapBuffer[EEP_POS_USER_SUM] =
DBusEMapBuffer[EEP_POS_USER_VOL] = VOICE_VOLUME_MAX;
I2CWrite24C02Array(EEP_ADR_USER_0, DBusEMapBuffer + EEP_ADR_USER_0, EEP_LEN_USER_0);
}
void VoiceByteSaveEEP(BYTE Addr, BYTE Data)
{
BYTE CheckSum;
if (Addr >= EEP_ADR_USER_0 && Addr < EEP_ADR_USER_0 + EEP_LEN_USER_0) {
CheckSum = DBusEMapBuffer[EEP_POS_USER_SUM] - DBusEMapBuffer[Addr] + Data;
DBusEMapBuffer[Addr] = Data;
I2CWrite24C02( Addr, Data);
DBusEMapBuffer[EEP_POS_USER_SUM] = CheckSum;
I2CWrite24C02( EEP_POS_USER_SUM, CheckSum);
}
}
#endif
#endif SUPPORT_VOICE
#ifdef SUPPORT_TEST_FUNCTION
void TestVoice()
{
#if 0
// BYTE VoiceString[] = "广州市丰凌电器有限公司ABC abc Road";
// BYTE VoiceString[] = "请稍候 广花高速 中山大道 环市东路 环市西路 解放北路 解放南路";
// BYTE VoiceString[] = "You are in Papakura street, 200 meters away from Sydenham road";
BYTE VoiceString[] = "ABC 风神大道。请稍候!吃了吗?你好吗?吃饭了没有?";
#if 0
UINT16 VoiceString[] = {
0xfffe, 0xcb8a, 0x2857, 0x4d52,
0xb965, 0x004e, 0x7e76, 0x6c51,
0x3a5c, 0x5586, 0x0cff, 0x6665,
0x1653, 0x5753, 0xef8d, 0xf353,
0x498f, 0x0230,
0x001a, };
#elif 0
UINT16 VoiceString[] = {
0xfffe,
0xf78b, 0x2857, 0x4d52,
0xb965, 0x004e, 0x7e76, 0x6c51,
0x3a5c, 0x0459, 0x0cff, 0x6665,
0x1653, 0x5753, 0xef8d, 0xf353,
0x6c8f, 0x0230,
0x001a, };
#endif
// psprintf(LineBuffer, "VOICE:%s", VoiceString);
// MenuPrintMessage(3);
#ifdef SUPPORT_VOICE
VoiceSend(VoiceString);
#endif
#else
static UINT16 Distance = 100;
psprintf(LineBuffer, "请在前方大约%d米处路口左转", Distance);
#ifdef SUPPORT_VOICE
VoiceSendQuene(LineBuffer, VOICE_LEVEL_HI);
#endif
Distance += 50;
#endif
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -