Skip to content
This repository has been archived by the owner on Aug 6, 2019. It is now read-only.

Commit

Permalink
Add Bing STT engine
Browse files Browse the repository at this point in the history
  • Loading branch information
Smanar committed Sep 19, 2016
1 parent 3ad39df commit 58765dc
Show file tree
Hide file tree
Showing 14 changed files with 664 additions and 371 deletions.
464 changes: 464 additions & 0 deletions rhonda/STTEngine.cpp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion rhonda/translategoogle.h → rhonda/STTEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@


int TranslateGoggle(char *buff, size_t s, char *resultat);
void SetGoogleApiKey(char *s);
void SetSTTApiKey(char *s);
int TranslateBing(char *Buff_flac, size_t s, char *resultat);

64 changes: 41 additions & 23 deletions rhonda/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
#define FRAMES_PER_BUFFER (512)
#define MAXSILENCE 900
#define MINSILENCE 500
#define MINFRAME 45000
#define MINFRAME 1.1f

#define MAGICNUMBER 8000

#define BUFFER

int fd = 0;

bool PortAudioInitialised = false;
Expand Down Expand Up @@ -389,7 +387,7 @@ int Checkamplitude(long value)
{
if (Enr_etat == ENR_ATTENTE)
{
wprintf(L"Son detecte, Demmarage enregistrement. Valeur : %ld\n",value);
wprintf(L"Sound detected, Start recording. Value : %ld\n",value);
_DisplaySpectro(-1);

Enr_etat = ENR_ENCOURS;
Expand All @@ -405,7 +403,7 @@ int Checkamplitude(long value)
{
if (Enr_etat != ENR_FINI)
{
wprintf(L"Too much silence.\n");
wprintf(L"Too much silence, stop recording.\n");
if (Enr_etat == ENR_ENCOURS) Enr_etat = ENR_FINI;
else Enr_etat = ENR_RATE;
}
Expand Down Expand Up @@ -460,7 +458,7 @@ static int recordCallback(const void *inputBuffer, void *outputBuffer, unsigned

if (framesLeft < framesPerBuffer)
{
wprintf(L"Depassement duree max\n");
wprintf(L"Recorded sound too long, stop recording\n");
framesToCalc = framesLeft;
finished = paComplete;
}
Expand Down Expand Up @@ -546,14 +544,16 @@ cRecord::cRecord()
data.recordedSamples = NULL;
hdr = NULL;

Defaut_sample_rate = SAMPLE_RATE;

hdr = (WaveHeader *)malloc(sizeof(*hdr));

wprintf(L"\033[0;31mInitialise sound recorder\033[0;37m\n");

InitPortAudio();

//making header
hdr = genericWAVHeader(hdr, SAMPLE_RATE, 8 * sizeof(SAMPLE), NUM_CHANNELS);
hdr = genericWAVHeader(hdr, Defaut_sample_rate, 8 * sizeof(SAMPLE), NUM_CHANNELS);
if (!hdr)
{
wprintf(L"Error allocating WAV header.\n");
Expand Down Expand Up @@ -615,9 +615,25 @@ void cRecord::Stop()
}
}

void cRecord::SetSampleRate(int v)
{
Defaut_sample_rate = v;

//Remake header
if (hdr) free(hdr);
hdr = (WaveHeader *)malloc(sizeof(*hdr));
hdr = genericWAVHeader(hdr, Defaut_sample_rate, 8 * sizeof(SAMPLE), NUM_CHANNELS);
if (!hdr)
{
wprintf(L"Error allocating WAV header.\n");
}

wprintf(L"Setting Sample rate : %d\n", v);

}

char * cRecord::RecordFLAC(uint32_t duration,size_t *sizeflac)

char * cRecord::RecordSound(uint32_t duration,size_t *sizeflac)
{

PaError err = paNoError;
Expand All @@ -629,8 +645,6 @@ char * cRecord::RecordFLAC(uint32_t duration,size_t *sizeflac)

Initchecker();



//ok start to recording
data.maxFrameIndex = MaxFrames = duration * hdr->sample_rate; /* Record for a few seconds. */
data.frameIndex = 0;
Expand Down Expand Up @@ -662,7 +676,7 @@ char * cRecord::RecordFLAC(uint32_t duration,size_t *sizeflac)
Stop();

wprintf(L"Nbre de frames = %d\n",data.frameIndex);
if (data.frameIndex < MINFRAME)
if (data.frameIndex < (hdr->sample_rate* MINFRAME))
{
wprintf(L"Fichier trop petit, nbre frame = %d < %d\n",data.frameIndex,MINFRAME);
return NULL;
Expand Down Expand Up @@ -693,7 +707,8 @@ char * cRecord::RecordFLAC(uint32_t duration,size_t *sizeflac)
average /= (double)numSamples;
#endif

#ifdef RAW
//Raw output
#if 0
{
FILE *fid;
fid = fopen("recorded.raw", "wb");
Expand All @@ -708,10 +723,13 @@ char * cRecord::RecordFLAC(uint32_t duration,size_t *sizeflac)
fclose( fid );
printf("Wrote data to 'recorded.raw'\n");
}
return NULL;
}
#elif FILE
#endif
//File output
#if 0
{
FILE* fid = fopen(fileName, "wb");
FILE* fid = fopen("output.wav", "wb");
if(!fid)
{
printf("Could not open file.");
Expand All @@ -724,12 +742,15 @@ char * cRecord::RecordFLAC(uint32_t duration,size_t *sizeflac)
fwrite(data.recordedSamples, NUM_CHANNELS * sizeof(SAMPLE), data.frameIndex, fid);
fclose(fid);
}

return NULL;
}
#else
#endif
//Buffer output
#if 1
{
char *WavBuffer;
int size;
char * buff_flac;

hdr->data_size = data.frameIndex * (NUM_CHANNELS * sizeof(SAMPLE));
size = hdr->data_size + 44;
Expand All @@ -739,14 +760,11 @@ char * cRecord::RecordFLAC(uint32_t duration,size_t *sizeflac)
writeWAVHeaderBuffer(WavBuffer,hdr);
memcpy(WavBuffer+44,data.recordedSamples,NUM_CHANNELS * sizeof(SAMPLE) * data.frameIndex);

//convert wav buffer to flac buffer
printf("Sound recorded, convertion to flac\n");
buff_flac = ConvertWavBufferToFlacBuffer(WavBuffer, NUM_CHANNELS * sizeof(SAMPLE) * data.frameIndex + 44, sizeflac);

if (WavBuffer) free(WavBuffer);
WavBuffer = NULL;
//return size
*sizeflac = NUM_CHANNELS * sizeof(SAMPLE) * data.frameIndex + 44;

return buff_flac;
//Return buffer
return WavBuffer;
}
#endif

Expand Down
5 changes: 4 additions & 1 deletion rhonda/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ class cRecord
cRecord();

// Méthodes
char * RecordFLAC(uint32_t duration, size_t *size);
char * RecordSound(uint32_t duration, size_t *size);
void Stop(void);
bool Start(void);
void SetSampleRate(int);

void SetSpectro(long);

Expand All @@ -146,6 +147,8 @@ class cRecord
PAData data;
PaStream* stream;

int Defaut_sample_rate;

//config


Expand Down
4 changes: 4 additions & 0 deletions rhonda/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<mesh name="mesh_root">
<!-- configuration -->
<config>
<!-- 0 = Google STT - 1 = Bing STT-->
<STTMode>0</STTMode>
<!-- API key -->
<api>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</api>
<!-- Special config -->
<ville>paris</ville>
<cinemaurl>http://www.commeaucinema.com/rsspage.php?feed=cine</cinemaurl>
<RSS_Site>http://www.site.com/forum/index.php?type=rss;action=.xml</RSS_Site>
Expand Down
2 changes: 1 addition & 1 deletion rhonda/flac.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ char * ConvertWavBufferToFlacBuffer(char *buff_wave, size_t size_wave,size_t *si
);

if (ok != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
fprintf(stderr, "ERROR: initializing encoder: %s\n", FLAC__StreamEncoderInitStatusString[init_status]);
fprintf(stderr, "ERROR: initializing encoder: %s\n", FLAC__StreamEncoderInitStatusString[ok]);
ok = false;

free(flac_data.buf);
Expand Down
20 changes: 10 additions & 10 deletions rhonda/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ DEP_DEBUG =
OUT_DEBUG = bin/Debug/rhonda

INC_RELEASE = $(INC) -Ilibs -Ilibs/portaudio
CFLAGS_RELEASE = $(CFLAGS) -O3 -std=c++0x -Wall
CFLAGS_RELEASE = $(CFLAGS) -O3 -std=c++0x -Wall -Wno-write-strings
RESINC_RELEASE = $(RESINC)
RCFLAGS_RELEASE = $(RCFLAGS)
LIBDIR_RELEASE = $(LIBDIR)
LIB_RELEASE = $(LIB)libs/libsnowboy-detect.a -lcblas libs/portaudio/libportaudio.a -llapack_atlas -lasound -ljack -lpthread -lrt -lm -ldl -lFLAC -lcurl -lwiringPi
LIB_RELEASE = $(LIB)libs/libsnowboy-detect.a -lcblas libs/portaudio/libportaudio.a -llapack_atlas -lasound -ljack -lpthread -lrt -lm -ldl -lFLAC -lcurl -lwiringPi -luuid
LDFLAGS_RELEASE = $(LDFLAGS) -s
OBJDIR_RELEASE = obj/Release
DEP_RELEASE =
OUT_RELEASE = bin/Release/rhonda

OBJ_DEBUG = $(OBJDIR_DEBUG)/applications.o $(OBJDIR_DEBUG)/audio.o $(OBJDIR_DEBUG)/flac.o $(OBJDIR_DEBUG)/fonction.o $(OBJDIR_DEBUG)/hardware.o $(OBJDIR_DEBUG)/libs/i2cbusses.o $(OBJDIR_DEBUG)/libs/pugixml.o $(OBJDIR_DEBUG)/libs/rs232.o $(OBJDIR_DEBUG)/libs/slre.o $(OBJDIR_DEBUG)/prog.o $(OBJDIR_DEBUG)/traitement.o $(OBJDIR_DEBUG)/translategoogle.o $(OBJDIR_DEBUG)/uart.o
OBJ_DEBUG = $(OBJDIR_DEBUG)/STTEngine.o $(OBJDIR_DEBUG)/applications.o $(OBJDIR_DEBUG)/audio.o $(OBJDIR_DEBUG)/flac.o $(OBJDIR_DEBUG)/fonction.o $(OBJDIR_DEBUG)/hardware.o $(OBJDIR_DEBUG)/libs/i2cbusses.o $(OBJDIR_DEBUG)/libs/pugixml.o $(OBJDIR_DEBUG)/libs/rs232.o $(OBJDIR_DEBUG)/libs/slre.o $(OBJDIR_DEBUG)/prog.o $(OBJDIR_DEBUG)/traitement.o $(OBJDIR_DEBUG)/uart.o

OBJ_RELEASE = $(OBJDIR_RELEASE)/applications.o $(OBJDIR_RELEASE)/audio.o $(OBJDIR_RELEASE)/flac.o $(OBJDIR_RELEASE)/fonction.o $(OBJDIR_RELEASE)/hardware.o $(OBJDIR_RELEASE)/libs/i2cbusses.o $(OBJDIR_RELEASE)/libs/pugixml.o $(OBJDIR_RELEASE)/libs/rs232.o $(OBJDIR_RELEASE)/libs/slre.o $(OBJDIR_RELEASE)/prog.o $(OBJDIR_RELEASE)/traitement.o $(OBJDIR_RELEASE)/translategoogle.o $(OBJDIR_RELEASE)/uart.o
OBJ_RELEASE = $(OBJDIR_RELEASE)/STTEngine.o $(OBJDIR_RELEASE)/applications.o $(OBJDIR_RELEASE)/audio.o $(OBJDIR_RELEASE)/flac.o $(OBJDIR_RELEASE)/fonction.o $(OBJDIR_RELEASE)/hardware.o $(OBJDIR_RELEASE)/libs/i2cbusses.o $(OBJDIR_RELEASE)/libs/pugixml.o $(OBJDIR_RELEASE)/libs/rs232.o $(OBJDIR_RELEASE)/libs/slre.o $(OBJDIR_RELEASE)/prog.o $(OBJDIR_RELEASE)/traitement.o $(OBJDIR_RELEASE)/uart.o

all: debug release

Expand All @@ -60,6 +60,9 @@ debug: before_debug out_debug after_debug
out_debug: before_debug $(OBJ_DEBUG) $(DEP_DEBUG)
$(LD) $(LIBDIR_DEBUG) -o $(OUT_DEBUG) $(OBJ_DEBUG) $(LDFLAGS_DEBUG) $(LIB_DEBUG)

$(OBJDIR_DEBUG)/STTEngine.o: STTEngine.cpp
$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c STTEngine.cpp -o $(OBJDIR_DEBUG)/STTEngine.o

$(OBJDIR_DEBUG)/applications.o: applications.cpp
$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c applications.cpp -o $(OBJDIR_DEBUG)/applications.o

Expand Down Expand Up @@ -93,9 +96,6 @@ $(OBJDIR_DEBUG)/prog.o: prog.cpp
$(OBJDIR_DEBUG)/traitement.o: traitement.cpp
$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c traitement.cpp -o $(OBJDIR_DEBUG)/traitement.o

$(OBJDIR_DEBUG)/translategoogle.o: translategoogle.cpp
$(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c translategoogle.cpp -o $(OBJDIR_DEBUG)/translategoogle.o

$(OBJDIR_DEBUG)/uart.o: uart.c
$(CC) $(CFLAGS_DEBUG) $(INC_DEBUG) -c uart.c -o $(OBJDIR_DEBUG)/uart.o

Expand All @@ -117,6 +117,9 @@ release: before_release out_release after_release
out_release: before_release $(OBJ_RELEASE) $(DEP_RELEASE)
$(LD) $(LIBDIR_RELEASE) -o $(OUT_RELEASE) $(OBJ_RELEASE) $(LDFLAGS_RELEASE) $(LIB_RELEASE)

$(OBJDIR_RELEASE)/STTEngine.o: STTEngine.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c STTEngine.cpp -o $(OBJDIR_RELEASE)/STTEngine.o

$(OBJDIR_RELEASE)/applications.o: applications.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c applications.cpp -o $(OBJDIR_RELEASE)/applications.o

Expand Down Expand Up @@ -150,9 +153,6 @@ $(OBJDIR_RELEASE)/prog.o: prog.cpp
$(OBJDIR_RELEASE)/traitement.o: traitement.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c traitement.cpp -o $(OBJDIR_RELEASE)/traitement.o

$(OBJDIR_RELEASE)/translategoogle.o: translategoogle.cpp
$(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c translategoogle.cpp -o $(OBJDIR_RELEASE)/translategoogle.o

$(OBJDIR_RELEASE)/uart.o: uart.c
$(CC) $(CFLAGS_RELEASE) $(INC_RELEASE) -c uart.c -o $(OBJDIR_RELEASE)/uart.o

Expand Down
Loading

0 comments on commit 58765dc

Please sign in to comment.