Merge branch 'master' of hackerspace.pl:q3k/hackfridge
commit
e320d8d22e
|
@ -25,7 +25,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
printf("Barcode initialization successful\n");
|
||||
|
||||
tts_speak("Refryżyrator gotowy do pracy.");
|
||||
tts_speak_cached("Refryżyrator gotowy do pracy.");
|
||||
|
||||
char MifareID[128];
|
||||
char Barcode[14];
|
||||
|
@ -43,14 +43,14 @@ int main(int argc, char **argv)
|
|||
{
|
||||
if (LDAPResult == NO_SUCH_CARD)
|
||||
{
|
||||
tts_speak("Nieznana karta.");
|
||||
tts_speak_cached("Nieznana karta.");
|
||||
printf("NFC: Unknown card.\n");
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
tts_speak("Błąd eldapa.");
|
||||
tts_speak_cached("Błąd eldapa.");
|
||||
printf("LDAP: Unknown error %i\n", LDAPResult);
|
||||
continue;
|
||||
}
|
||||
|
@ -60,11 +60,12 @@ int main(int argc, char **argv)
|
|||
ldap_uid_from_dn(DN, UID);
|
||||
printf("LDAP uid: %s\n", UID);
|
||||
|
||||
tts_speak("Zeskanuj produkt.\n");
|
||||
tts_speak_cached("Zeskanuj produkt.\n");
|
||||
|
||||
int BarcodeResult = barcode_read(Barcode);
|
||||
if (BarcodeResult == 0)
|
||||
{
|
||||
tts_speak_cached("bip");
|
||||
printf("Scanned barcode %s\n", Barcode);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -2,15 +2,73 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#include "base64.h"
|
||||
|
||||
static char *g_IvonaURL = "http://www.ivona.com/online/fileSentence.php?l=en&e=0&v=1&t=%s";
|
||||
|
||||
size_t tts_write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
void _tts_digest(char *Text, char *DigestOut)
|
||||
{
|
||||
int written = fwrite(ptr, size, nmemb, stream);
|
||||
return written;
|
||||
unsigned char Digest[32];
|
||||
|
||||
SHA256_CTX SHA;
|
||||
memset(Digest, 0, 32);
|
||||
SHA256_Init(&SHA);
|
||||
SHA256_Update(&SHA, "hf-tts", 6);
|
||||
SHA256_Update(&SHA, Text, strlen(Text));
|
||||
SHA256_Final(Digest, &SHA);
|
||||
|
||||
for (int i = 0; i < 32; i++)
|
||||
sprintf(DigestOut + 2 * i, "%02x", Digest[i]);
|
||||
|
||||
DigestOut[64] = 0;
|
||||
}
|
||||
|
||||
void tts_speak_cached(char *Text)
|
||||
{
|
||||
char CachePath[128];
|
||||
strcpy(CachePath, "/tmp/hftts-");
|
||||
_tts_digest(Text, CachePath + 11);
|
||||
CachePath[11 + 64] = 0;
|
||||
|
||||
int B64OutputLength;
|
||||
char *B64Output = (char *)malloc(strlen(Text) * 2);
|
||||
bin_to_b64(B64Output, Text, strlen(Text));
|
||||
|
||||
char *URL = (char *)malloc(strlen(B64Output) + strlen(g_IvonaURL));
|
||||
sprintf(URL, g_IvonaURL, B64Output);
|
||||
|
||||
FILE *File = fopen(CachePath, "r");
|
||||
if (File)
|
||||
{
|
||||
printf("Cache hit on \"%s\" [%s]\n", Text, CachePath);
|
||||
fclose(File);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Cache miss on \"%s\" [%s]\n", Text, CachePath);
|
||||
char *CommandLine = malloc(256);
|
||||
sprintf(CommandLine, "curl -L -s -A Mozilla \"%s\" > %s", URL, CachePath);
|
||||
printf("Executing %s...\n", CommandLine);
|
||||
system(CommandLine);
|
||||
|
||||
free(CommandLine);
|
||||
}
|
||||
|
||||
if (!fork())
|
||||
{
|
||||
char *CommandLineChild = malloc(strlen(URL) + 100);
|
||||
sprintf(CommandLineChild, "mpg123 -2 -q %s", CachePath);
|
||||
printf("Executing %s...\n", CommandLineChild);
|
||||
system(CommandLineChild);
|
||||
free(CommandLineChild);
|
||||
printf("Child slave exiting.\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
free((void *)URL);
|
||||
free((void *)B64Output);
|
||||
}
|
||||
|
||||
void tts_speak(char *Text)
|
||||
|
|
|
@ -2,5 +2,6 @@
|
|||
#define __TTS_H__
|
||||
|
||||
void tts_speak(char *Text);
|
||||
void tts_speak_cached(char *Text);
|
||||
|
||||
#endif
|
||||
|
|
Reference in New Issue