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

Commit

Permalink
Rhonda can now record wav, convert to flac and send it to google with…
Browse files Browse the repository at this point in the history
…out using intermediate file.

Rhonda can now record wav, convert to flac and send it to google without
using intermediate file.
  • Loading branch information
Smanar committed Aug 7, 2016
1 parent 6c079d0 commit f382697
Show file tree
Hide file tree
Showing 13 changed files with 1,250 additions and 118 deletions.
939 changes: 939 additions & 0 deletions audio.cpp

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions rhonda/applications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,37 @@ int GetMeteo(wchar_t *s)

}

/*******************************************************************************/
#ifdef _WIN32
char * FindFile(char * path, char *f, char *ret)
{
return NULL;
}
#else
#include <dirent.h>

char * FindFile(char * path, char *f, char *ret)
{
DIR *d;
struct dirent *dir;

d = opendir("path");
if (d)
{
while ((dir = readdir(d)) != NULL)
{
if (strstr(dir->d_name, f))
{
wprintf(L"%s\n", dir->d_name);
}
}

closedir(d);
}
}

#endif

/*******************************************************************************/

int GetDefinition(char *mot, wchar_t * def)
Expand Down
2 changes: 2 additions & 0 deletions rhonda/applications.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ int RSSMonitor();

int GetFilmCinema(wchar_t *s,int l);

char * FindFile(char * path, char *f, char *ret);

void Savedata(void);

24 changes: 15 additions & 9 deletions rhonda/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ void cRecord::Stop()



int cRecord::RecordFLAC(const char *fileName, uint32_t duration)
char * cRecord::RecordFLAC(uint32_t duration,size_t *sizeflac)
{

PaError err = paNoError;
Expand All @@ -640,12 +640,12 @@ int cRecord::RecordFLAC(const char *fileName, uint32_t duration)
if(!data.recordedSamples)
{
wprintf(L"Could not allocate record array.\n");
return 0;
return NULL;
}

for(i = 0; i < numSamples; i++) data.recordedSamples[i] = 0;

if (!(Start())) return 0;
if (!(Start())) return NULL;


wprintf(L"Now recording!! Please speak into the microphone.\n");
Expand All @@ -657,21 +657,21 @@ int cRecord::RecordFLAC(const char *fileName, uint32_t duration)
Pa_Sleep(1000);
//wprintf(L"index = %d\n", data.frameIndex);
}
if (err < 0) return 0;
if (err < 0) return NULL;

Stop();

wprintf(L"Nbre de frames = %d\n",data.frameIndex);
if (data.frameIndex < MINFRAME)
{
wprintf(L"Fichier trop petit, nbre frame = %d < %d\n",data.frameIndex,MINFRAME);
return 0;
return NULL;
}

if (Enr_etat == ENR_RATE)
{
wprintf(L"Recording cancelled\n");
return 0;
return NULL;
}


Expand Down Expand Up @@ -729,22 +729,28 @@ int cRecord::RecordFLAC(const char *fileName, uint32_t duration)
{
char *WavBuffer;
int size;
char * buff_flac;

hdr->data_size = data.frameIndex * (NUM_CHANNELS * sizeof(SAMPLE));
size = hdr->data_size + 44;

//convert buffer data wav to flac
//Save wav in buffer
WavBuffer = (char*) malloc (size * sizeof(char));
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");
ConvertFlacBuffer(WavBuffer,size, fileName);
buff_flac = ConvertWavBufferToFlacBuffer(WavBuffer, NUM_CHANNELS * sizeof(SAMPLE) * data.frameIndex + 44, sizeflac);

if (WavBuffer) free(WavBuffer);
WavBuffer = NULL;

return buff_flac;
}
#endif

return 1;
return NULL;
}

/**************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion rhonda/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class cRecord
cRecord();

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

Expand Down
3 changes: 2 additions & 1 deletion rhonda/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<LC command="affiche icone tete///" action = "17" />
<LC command="*QUESTION de neuf///" action = "19" />
<LC command="question vie univers///" action = "21" />

<LC command="recherche le fichier///" action = "22" />
</commandlist>
<!-- dictionnaire special -->
<special>
Expand Down Expand Up @@ -83,6 +83,7 @@
<ACT index="19" action="SHOWICON 8 | CHECKMAIL 1| CHECKGITHUB 1| CHECKRSS 1" />
<ACT index="20" action="SENDREQUEST http://xx.xx.xx.xx:8080/json.htm?type=command&amp;param=switchlight&amp;idx=220&amp;switchcmd=On" />
<ACT index="21" action="DIRE la réponse est 42" />
<ACT index="22" action="FINDFILE" />
</action>
<!-- icones pour la matrice -->
<!-- 1=sablier 2=micro 3=smiley 4=interrogation 5/6=anim alien 7=coeur 8=clock 9=mail-->
Expand Down
Loading

0 comments on commit f382697

Please sign in to comment.