From 3c887fd06a0a6790db978d13df4cc73f6d5b75b0 Mon Sep 17 00:00:00 2001
From: Carl Worth <cworth@cworth.org>
Date: Wed, 9 Jun 2010 07:42:26 -0700
Subject: [PATCH] Add a simple text-to-speech challenge type.

This is implemented by doing the following:

     echo $challenge | festival --tts

But we actually make that invocation in a little script named mnemon-tts
because I'm too lazy to code up a custom invocation for this challenge
type.
---
 mnemon-tts | 10 ++++++++++
 mnemon.c   | 11 ++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100755 mnemon-tts

diff --git a/mnemon-tts b/mnemon-tts
new file mode 100755
index 0000000..d4825ce
--- /dev/null
+++ b/mnemon-tts
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+arg="$@"
+
+# Strip undesired directory component
+dir=$(dirname "$arg")
+
+text="${arg#$dir/}"
+
+echo "$text" | festival --tts
diff --git a/mnemon.c b/mnemon.c
index 69ac5b1..3dee034 100644
--- a/mnemon.c
+++ b/mnemon.c
@@ -65,7 +65,8 @@ typedef enum {
     CHALLENGE_TYPE_TEXT,
     CHALLENGE_TYPE_IMAGE,
     CHALLENGE_TYPE_AUDIO,
-    CHALLENGE_TYPE_MIDI
+    CHALLENGE_TYPE_MIDI,
+    CHALLENGE_TYPE_TEXT_TO_SPEECH
 } challenge_type_t;
 
 typedef struct _category {
@@ -295,6 +296,9 @@ category_print (category_t	*category,
     case CHALLENGE_TYPE_MIDI:
 	fprintf (file, "midi");
 	break;
+    case CHALLENGE_TYPE_TEXT_TO_SPEECH:
+	fprintf	(file, "text-to-speech");
+	break;
     }
     fprintf (file, "\n\n");
 
@@ -665,6 +669,8 @@ mnemon_load_category (mnemon_t		*mnemon,
 		category->challenge_type = CHALLENGE_TYPE_AUDIO;
 	    } else if (strcmp (value, "midi") == 0) {
 		category->challenge_type = CHALLENGE_TYPE_MIDI;
+	    } else if (strcmp (value, "text-to-speech") == 0) {
+		category->challenge_type = CHALLENGE_TYPE_TEXT_TO_SPEECH;
 	    } else {
 		fprintf (stderr, "Unknown value for \"challenge\" option \"%s\" at %s:%d\n",
 			 value, path, line_count);
@@ -1208,6 +1214,9 @@ mnemon_show_challenge (mnemon_t *mnemon,
     case CHALLENGE_TYPE_MIDI:
 	program = "timidity -Os";
 	break;
+    case CHALLENGE_TYPE_TEXT_TO_SPEECH:
+	program = "mnemon-tts";
+	break;
     }
 
     xasprintf (&command, "%s %s/%s >/dev/null 2>&1 &",
-- 
2.45.2