transcribe raw audio
This commit is contained in:
@@ -33,6 +33,7 @@ size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userdata) {
|
|||||||
// Returns string that caller must free
|
// Returns string that caller must free
|
||||||
char* find_transcript(char* json_response)
|
char* find_transcript(char* json_response)
|
||||||
{
|
{
|
||||||
|
printf("Parsing response: %s \n", json_response);
|
||||||
char* start = strstr(json_response, "\"transcript\":\"");
|
char* start = strstr(json_response, "\"transcript\":\"");
|
||||||
if (!start) return NULL;
|
if (!start) return NULL;
|
||||||
|
|
||||||
@@ -61,6 +62,8 @@ size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp) {
|
|||||||
response->size += total_size;
|
response->size += total_size;
|
||||||
response->data[response->size] = '\0'; // Null terminate
|
response->data[response->size] = '\0'; // Null terminate
|
||||||
|
|
||||||
|
printf("read an extra %d bytes of data\n", (int)total_size);
|
||||||
|
|
||||||
return total_size;
|
return total_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,9 +91,8 @@ char* transcribe(FILE* audio_file) {
|
|||||||
if (curl) {
|
if (curl) {
|
||||||
// Set headers for Deepgram API
|
// Set headers for Deepgram API
|
||||||
headers = curl_slist_append(headers, "Authorization: Token YOUR_DEEPGRAM_API_KEY");
|
headers = curl_slist_append(headers, "Authorization: Token YOUR_DEEPGRAM_API_KEY");
|
||||||
headers = curl_slist_append(headers, "Content-Type: audio/*");
|
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, "https://api.deepgram.com/v1/listen");
|
curl_easy_setopt(curl, CURLOPT_URL, "https://api.deepgram.com/v1/listen?encoding=linear16&sample_rate=48000&channels=1");
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||||
curl_easy_setopt(curl, CURLOPT_POST, 1L);
|
curl_easy_setopt(curl, CURLOPT_POST, 1L);
|
||||||
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
|
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
|
||||||
@@ -108,6 +110,8 @@ char* transcribe(FILE* audio_file) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("done performing curl\n");
|
||||||
|
|
||||||
curl_slist_free_all(headers);
|
curl_slist_free_all(headers);
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
}
|
}
|
||||||
@@ -214,9 +218,8 @@ int main() {
|
|||||||
perror("Error opening file");
|
perror("Error opening file");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
printf("======READING FRAMES for 5 seconds========\n");
|
||||||
while (snd_pcm_readi(pcm_handle, (void *)buf, period_size) > 0 && periods_read < periods_to_read) {
|
while (snd_pcm_readi(pcm_handle, (void *)buf, period_size) > 0 && periods_read < periods_to_read) {
|
||||||
printf("======READING FRAMES========\n");
|
|
||||||
|
|
||||||
// Because each frame is 2 bytes (format/bit rate), cast to int16
|
// Because each frame is 2 bytes (format/bit rate), cast to int16
|
||||||
// int16_t *samples = (int16_t *)buf;
|
// int16_t *samples = (int16_t *)buf;
|
||||||
// for (int i = 0; i < period_size; i++) {
|
// for (int i = 0; i < period_size; i++) {
|
||||||
@@ -224,10 +227,9 @@ int main() {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
fwrite(buf, sizeof(int16_t), period_size, file);
|
fwrite(buf, sizeof(int16_t), period_size, file);
|
||||||
|
|
||||||
printf("\n");
|
|
||||||
periods_read++;
|
periods_read++;
|
||||||
}
|
}
|
||||||
|
printf("done capturing audio\n");
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
@@ -238,10 +240,14 @@ int main() {
|
|||||||
if (transcript) {
|
if (transcript) {
|
||||||
printf("Transcript: %s\n", transcript);
|
printf("Transcript: %s\n", transcript);
|
||||||
free(transcript);
|
free(transcript);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "unable to get transcript");
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "unable to open file for reading\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
free((void *)buf);
|
free((void *)buf);
|
||||||
snd_pcm_close(pcm_handle);
|
snd_pcm_close(pcm_handle);
|
||||||
snd_pcm_hw_params_free(params);
|
snd_pcm_hw_params_free(params);
|
||||||
|
|||||||
Reference in New Issue
Block a user