/* whisper.c generated by valac 0.56.19, the Vala compiler
 * generated from whisper.vala, do not modify */

#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <glib/gstdio.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define DC_TYPE_TRANSCRIBER (dc_transcriber_get_type ())
#define DC_TRANSCRIBER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DC_TYPE_TRANSCRIBER, DcTranscriber))
#define DC_TRANSCRIBER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DC_TYPE_TRANSCRIBER, DcTranscriberClass))
#define DC_IS_TRANSCRIBER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DC_TYPE_TRANSCRIBER))
#define DC_IS_TRANSCRIBER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DC_TYPE_TRANSCRIBER))
#define DC_TRANSCRIBER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DC_TYPE_TRANSCRIBER, DcTranscriberClass))

typedef struct _DcTranscriber DcTranscriber;
typedef struct _DcTranscriberClass DcTranscriberClass;
typedef struct _DcTranscriberPrivate DcTranscriberPrivate;
enum  {
	DC_TRANSCRIBER_0_PROPERTY,
	DC_TRANSCRIBER_NUM_PROPERTIES
};
static GParamSpec* dc_transcriber_properties[DC_TRANSCRIBER_NUM_PROPERTIES];
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _DcTranscriberRunWhisperData DcTranscriberRunWhisperData;
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
enum  {
	DC_TRANSCRIBER_UPDATED_SIGNAL,
	DC_TRANSCRIBER_NUM_SIGNALS
};
static guint dc_transcriber_signals[DC_TRANSCRIBER_NUM_SIGNALS] = {0};

struct _DcTranscriber {
	GObject parent_instance;
	DcTranscriberPrivate * priv;
};

struct _DcTranscriberClass {
	GObjectClass parent_class;
};

struct _DcTranscriberPrivate {
	GHashTable* results;
	GHashTable* running;
};

struct _DcTranscriberRunWhisperData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DcTranscriber* self;
	gchar* path;
	gchar* text;
	gchar* _tmp0_;
	gchar** argv;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar** _tmp9_;
	gint argv_length1;
	gint _argv_size_;
	GSubprocessLauncher* launcher;
	GSubprocessLauncher* _tmp10_;
	GSubprocessLauncher* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	GSubprocess* proc;
	GSubprocessLauncher* _tmp14_;
	gchar** _tmp15_;
	gint _tmp15__length1;
	GSubprocess* _tmp16_;
	gchar* stdout_buf;
	gchar* stderr_buf;
	GSubprocess* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	const gchar* _tmp20_;
	const gchar* _tmp21_;
	gchar* _tmp22_;
	GError* e;
	GError* _tmp23_;
	const gchar* _tmp24_;
	GHashTable* _tmp25_;
	GHashTable* _tmp26_;
	gchar* _tmp27_;
	const gchar* _tmp28_;
	gchar* _tmp29_;
	GError* _inner_error0_;
};

static gint DcTranscriber_private_offset;
static gpointer dc_transcriber_parent_class = NULL;
static DcTranscriber* dc_transcriber_instance;
static DcTranscriber* dc_transcriber_instance = NULL;

VALA_EXTERN GType dc_transcriber_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (DcTranscriber, g_object_unref)
static void _g_free0_ (gpointer var);
VALA_EXTERN DcTranscriber* dc_transcriber_shared (void);
VALA_EXTERN DcTranscriber* dc_transcriber_new (void);
VALA_EXTERN DcTranscriber* dc_transcriber_construct (GType object_type);
VALA_EXTERN gboolean dc_transcriber_available (void);
VALA_EXTERN gchar* dc_transcriber_result_for (DcTranscriber* self,
                                  const gchar* path);
VALA_EXTERN gboolean dc_transcriber_is_running (DcTranscriber* self,
                                    const gchar* path);
VALA_EXTERN void dc_transcriber_transcribe (DcTranscriber* self,
                                const gchar* path);
static void dc_transcriber_run_whisper (DcTranscriber* self,
                                 const gchar* path,
                                 GAsyncReadyCallback _callback_,
                                 gpointer _user_data_);
static void dc_transcriber_run_whisper_finish (DcTranscriber* self,
                                        GAsyncResult* _res_);
static void dc_transcriber_run_whisper_data_free (gpointer _data);
static gboolean dc_transcriber_run_whisper_co (DcTranscriberRunWhisperData* _data_);
static gchar* dc_transcriber_work_dir (void);
VALA_EXTERN GSubprocess* dc_subprocess_util_spawnv (GSubprocessLauncher* launcher,
                                        gchar** argv,
                                        gint argv_length1,
                                        GError** error);
static void dc_transcriber_run_whisper_ready (GObject* source_object,
                                       GAsyncResult* _res_,
                                       gpointer _user_data_);
VALA_EXTERN gchar* dc_transcriber_parse_output (const gchar* output);
static void dc_transcriber_finalize (GObject * obj);
static GType dc_transcriber_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static gssize _vala_array_length (gpointer array);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dc_transcriber_get_instance_private (DcTranscriber* self)
{
	return G_STRUCT_MEMBER_P (self, DcTranscriber_private_offset);
}

static void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

DcTranscriber*
dc_transcriber_shared (void)
{
	DcTranscriber* _tmp0_;
	DcTranscriber* _tmp2_;
	DcTranscriber* _tmp3_;
	DcTranscriber* result;
	_tmp0_ = dc_transcriber_instance;
	if (_tmp0_ == NULL) {
		DcTranscriber* _tmp1_;
		_tmp1_ = dc_transcriber_new ();
		_g_object_unref0 (dc_transcriber_instance);
		dc_transcriber_instance = _tmp1_;
	}
	_tmp2_ = dc_transcriber_instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

gboolean
dc_transcriber_available (void)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gboolean _tmp2_;
	gboolean result;
	_tmp0_ = g_find_program_in_path ("whisper");
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_ != NULL;
	_g_free0 (_tmp1_);
	result = _tmp2_;
	return result;
}

/** Finished transcription for path, or null when none ran yet. An
            empty string means the tool produced no usable output. */
gchar*
dc_transcriber_result_for (DcTranscriber* self,
                           const gchar* path)
{
	GHashTable* _tmp0_;
	gconstpointer _tmp1_;
	gchar* _tmp2_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (path != NULL, NULL);
	_tmp0_ = self->priv->results;
	_tmp1_ = g_hash_table_lookup (_tmp0_, path);
	_tmp2_ = g_strdup ((const gchar*) _tmp1_);
	result = _tmp2_;
	return result;
}

gboolean
dc_transcriber_is_running (DcTranscriber* self,
                           const gchar* path)
{
	GHashTable* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (path != NULL, FALSE);
	_tmp0_ = self->priv->running;
	result = g_hash_table_contains (_tmp0_, path);
	return result;
}

void
dc_transcriber_transcribe (DcTranscriber* self,
                           const gchar* path)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (path != NULL);
	if (dc_transcriber_available ()) {
		GHashTable* _tmp2_;
		_tmp2_ = self->priv->running;
		_tmp1_ = !g_hash_table_contains (_tmp2_, path);
	} else {
		_tmp1_ = FALSE;
	}
	if (_tmp1_) {
		GHashTable* _tmp3_;
		_tmp3_ = self->priv->results;
		_tmp0_ = !g_hash_table_contains (_tmp3_, path);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		GHashTable* _tmp4_;
		gchar* _tmp5_;
		_tmp4_ = self->priv->running;
		_tmp5_ = g_strdup (path);
		g_hash_table_add (_tmp4_, _tmp5_);
		dc_transcriber_run_whisper (self, path, NULL, NULL);
	}
	g_signal_emit (self, dc_transcriber_signals[DC_TRANSCRIBER_UPDATED_SIGNAL], 0, path);
}

static void
dc_transcriber_run_whisper_data_free (gpointer _data)
{
	DcTranscriberRunWhisperData* _data_;
	_data_ = _data;
	_g_free0 (_data_->path);
	_g_object_unref0 (_data_->self);
	g_slice_free (DcTranscriberRunWhisperData, _data_);
}

static void
dc_transcriber_run_whisper (DcTranscriber* self,
                            const gchar* path,
                            GAsyncReadyCallback _callback_,
                            gpointer _user_data_)
{
	DcTranscriberRunWhisperData* _data_;
	DcTranscriber* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (path != NULL);
	_data_ = g_slice_new0 (DcTranscriberRunWhisperData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dc_transcriber_run_whisper_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = g_strdup (path);
	_g_free0 (_data_->path);
	_data_->path = _tmp1_;
	dc_transcriber_run_whisper_co (_data_);
}

static void
dc_transcriber_run_whisper_finish (DcTranscriber* self,
                                   GAsyncResult* _res_)
{
	DcTranscriberRunWhisperData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
}

static void
dc_transcriber_run_whisper_ready (GObject* source_object,
                                  GAsyncResult* _res_,
                                  gpointer _user_data_)
{
	DcTranscriberRunWhisperData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dc_transcriber_run_whisper_co (_data_);
}

static gboolean
dc_transcriber_run_whisper_co (DcTranscriberRunWhisperData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = g_strdup ("");
	_data_->text = _data_->_tmp0_;
	{
		_data_->_tmp1_ = g_strdup ("whisper");
		_data_->_tmp2_ = g_strdup (_data_->path);
		_data_->_tmp3_ = g_strdup ("--model");
		_data_->_tmp4_ = g_strdup ("base");
		_data_->_tmp5_ = g_strdup ("--output_format");
		_data_->_tmp6_ = g_strdup ("txt");
		_data_->_tmp7_ = g_strdup ("--fp16");
		_data_->_tmp8_ = g_strdup ("False");
		_data_->_tmp9_ = g_new0 (gchar*, 8 + 1);
		_data_->_tmp9_[0] = _data_->_tmp1_;
		_data_->_tmp9_[1] = _data_->_tmp2_;
		_data_->_tmp9_[2] = _data_->_tmp3_;
		_data_->_tmp9_[3] = _data_->_tmp4_;
		_data_->_tmp9_[4] = _data_->_tmp5_;
		_data_->_tmp9_[5] = _data_->_tmp6_;
		_data_->_tmp9_[6] = _data_->_tmp7_;
		_data_->_tmp9_[7] = _data_->_tmp8_;
		_data_->argv = _data_->_tmp9_;
		_data_->argv_length1 = 8;
		_data_->_argv_size_ = _data_->argv_length1;
		_data_->_tmp10_ = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_SILENCE);
		_data_->launcher = _data_->_tmp10_;
		_data_->_tmp11_ = _data_->launcher;
		_data_->_tmp12_ = dc_transcriber_work_dir ();
		_data_->_tmp13_ = _data_->_tmp12_;
		g_subprocess_launcher_set_cwd (_data_->_tmp11_, _data_->_tmp13_);
		_g_free0 (_data_->_tmp13_);
		_data_->_tmp14_ = _data_->launcher;
		_data_->_tmp15_ = _data_->argv;
		_data_->_tmp15__length1 = _data_->argv_length1;
		_data_->_tmp16_ = dc_subprocess_util_spawnv (_data_->_tmp14_, _data_->_tmp15_, (gint) _data_->_tmp15__length1, &_data_->_inner_error0_);
		_data_->proc = _data_->_tmp16_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->launcher);
			_data_->argv = (_vala_array_free (_data_->argv, _data_->argv_length1, (GDestroyNotify) g_free), NULL);
			goto __catch0_g_error;
		}
		_data_->_tmp17_ = _data_->proc;
		_data_->_tmp18_ = NULL;
		_data_->_tmp19_ = NULL;
		_data_->_state_ = 1;
		g_subprocess_communicate_utf8_async (_data_->_tmp17_, NULL, NULL, dc_transcriber_run_whisper_ready, _data_);
		return FALSE;
		_state_1:
		g_subprocess_communicate_utf8_finish (_data_->_tmp17_, _data_->_res_, &_data_->_tmp18_, &_data_->_tmp19_, &_data_->_inner_error0_);
		_g_free0 (_data_->stdout_buf);
		_data_->stdout_buf = _data_->_tmp18_;
		_g_free0 (_data_->stderr_buf);
		_data_->stderr_buf = _data_->_tmp19_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_free0 (_data_->stderr_buf);
			_g_free0 (_data_->stdout_buf);
			_g_object_unref0 (_data_->proc);
			_g_object_unref0 (_data_->launcher);
			_data_->argv = (_vala_array_free (_data_->argv, _data_->argv_length1, (GDestroyNotify) g_free), NULL);
			goto __catch0_g_error;
		}
		_data_->_tmp21_ = _data_->stdout_buf;
		_data_->_tmp20_ = _data_->_tmp21_;
		if (_data_->_tmp20_ == NULL) {
			_data_->_tmp20_ = "";
		}
		_data_->_tmp22_ = dc_transcriber_parse_output (_data_->_tmp20_);
		_g_free0 (_data_->text);
		_data_->text = _data_->_tmp22_;
		_g_free0 (_data_->stderr_buf);
		_g_free0 (_data_->stdout_buf);
		_g_object_unref0 (_data_->proc);
		_g_object_unref0 (_data_->launcher);
		_data_->argv = (_vala_array_free (_data_->argv, _data_->argv_length1, (GDestroyNotify) g_free), NULL);
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp23_ = _data_->e;
		_data_->_tmp24_ = _data_->_tmp23_->message;
		g_warning ("whisper.vala:72: transcribe: %s failed: %s", _data_->path, _data_->_tmp24_);
		_g_error_free0 (_data_->e);
	}
	__finally0:
	if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
		_g_free0 (_data_->text);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	_data_->_tmp25_ = _data_->self->priv->running;
	g_hash_table_remove (_data_->_tmp25_, _data_->path);
	_data_->_tmp26_ = _data_->self->priv->results;
	_data_->_tmp27_ = g_strdup (_data_->path);
	_data_->_tmp28_ = _data_->text;
	_data_->_tmp29_ = g_strdup (_data_->_tmp28_);
	g_hash_table_insert (_data_->_tmp26_, _data_->_tmp27_, _data_->_tmp29_);
	g_signal_emit (_data_->self, dc_transcriber_signals[DC_TRANSCRIBER_UPDATED_SIGNAL], 0, _data_->path);
	_g_free0 (_data_->text);
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static gchar*
dc_transcriber_work_dir (void)
{
	gchar* dir = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	_tmp0_ = g_get_user_cache_dir ();
	_tmp1_ = g_build_filename (_tmp0_, "parla", "transcribe", NULL);
	dir = _tmp1_;
	g_mkdir_with_parents (dir, 0700);
	result = dir;
	return result;
}

/**
         * The python tool ignores --output_format on stdout, so scrape its
         * human-readable progress lines instead:
         *   [00:00.800 --> 00:07.160]  Si no me escribes por Telegram...
         * Every line starting with '[' contributes the text after its first
         * ']'; everything else (warnings, language detection) is noise.
         */
static gint
string_index_of (const gchar* self,
                 const gchar* needle,
                 gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (needle != NULL, -1);
	_tmp0_ = strstr (((gchar*) self) + start_index, (gchar*) needle);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

gchar*
dc_transcriber_parse_output (const gchar* output)
{
	GString* sb = NULL;
	GString* _tmp0_;
	gchar** _tmp1_;
	gchar** _tmp2_;
	GString* _tmp18_;
	const gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* result;
	g_return_val_if_fail (output != NULL, NULL);
	_tmp0_ = g_string_new ("");
	sb = _tmp0_;
	_tmp2_ = _tmp1_ = g_strsplit (output, "\n", 0);
	{
		gchar** line_collection = NULL;
		gint line_collection_length1 = 0;
		gint _line_collection_size_ = 0;
		gint line_it = 0;
		line_collection = _tmp2_;
		line_collection_length1 = _vala_array_length (_tmp1_);
		for (line_it = 0; line_it < line_collection_length1; line_it = line_it + 1) {
			gchar* _tmp3_;
			gchar* line = NULL;
			_tmp3_ = g_strdup (line_collection[line_it]);
			line = _tmp3_;
			{
				const gchar* _tmp4_;
				gint idx = 0;
				const gchar* _tmp5_;
				gchar* text = NULL;
				const gchar* _tmp6_;
				gchar* _tmp7_;
				gchar* _tmp8_;
				gchar* _tmp9_;
				gchar* _tmp10_;
				const gchar* _tmp11_;
				gint _tmp12_;
				gint _tmp13_;
				GString* _tmp14_;
				GString* _tmp16_;
				const gchar* _tmp17_;
				_tmp4_ = line;
				if (!g_str_has_prefix (_tmp4_, "[")) {
					_g_free0 (line);
					continue;
				}
				_tmp5_ = line;
				idx = string_index_of (_tmp5_, "]", 0);
				if (idx < 0) {
					_g_free0 (line);
					continue;
				}
				_tmp6_ = line;
				_tmp7_ = string_substring (_tmp6_, (glong) (idx + 1), (glong) -1);
				_tmp8_ = _tmp7_;
				_tmp9_ = string_strip (_tmp8_);
				_tmp10_ = _tmp9_;
				_g_free0 (_tmp8_);
				text = _tmp10_;
				_tmp11_ = text;
				_tmp12_ = strlen (_tmp11_);
				_tmp13_ = _tmp12_;
				if (_tmp13_ == 0) {
					_g_free0 (text);
					_g_free0 (line);
					continue;
				}
				_tmp14_ = sb;
				if (_tmp14_->len > ((gssize) 0)) {
					GString* _tmp15_;
					_tmp15_ = sb;
					g_string_append_c (_tmp15_, '\n');
				}
				_tmp16_ = sb;
				_tmp17_ = text;
				g_string_append (_tmp16_, _tmp17_);
				_g_free0 (text);
				_g_free0 (line);
			}
		}
		line_collection = (_vala_array_free (line_collection, line_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	_tmp18_ = sb;
	_tmp19_ = _tmp18_->str;
	_tmp20_ = g_strdup (_tmp19_);
	result = _tmp20_;
	_g_string_free0 (sb);
	return result;
}

DcTranscriber*
dc_transcriber_construct (GType object_type)
{
	DcTranscriber * self = NULL;
	self = (DcTranscriber*) g_object_new (object_type, NULL);
	return self;
}

DcTranscriber*
dc_transcriber_new (void)
{
	return dc_transcriber_construct (DC_TYPE_TRANSCRIBER);
}

static void
dc_transcriber_class_init (DcTranscriberClass * klass,
                           gpointer klass_data)
{
	dc_transcriber_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DcTranscriber_private_offset);
	G_OBJECT_CLASS (klass)->finalize = dc_transcriber_finalize;
	/** Emitted when the transcription state for a file path changes. */
	dc_transcriber_signals[DC_TRANSCRIBER_UPDATED_SIGNAL] = g_signal_new ("updated", DC_TYPE_TRANSCRIBER, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
}

static void
dc_transcriber_instance_init (DcTranscriber * self,
                              gpointer klass)
{
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GHashTable* _tmp2_;
	GHashFunc _tmp3_;
	GEqualFunc _tmp4_;
	GHashTable* _tmp5_;
	self->priv = dc_transcriber_get_instance_private (self);
	_tmp0_ = g_str_hash;
	_tmp1_ = g_str_equal;
	_tmp2_ = g_hash_table_new_full (_tmp0_, _tmp1_, _g_free0_, _g_free0_);
	self->priv->results = _tmp2_;
	_tmp3_ = g_str_hash;
	_tmp4_ = g_str_equal;
	_tmp5_ = g_hash_table_new_full (_tmp3_, _tmp4_, NULL, _g_free0_);
	self->priv->running = _tmp5_;
}

static void
dc_transcriber_finalize (GObject * obj)
{
	DcTranscriber * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DC_TYPE_TRANSCRIBER, DcTranscriber);
	_g_hash_table_unref0 (self->priv->results);
	_g_hash_table_unref0 (self->priv->running);
	G_OBJECT_CLASS (dc_transcriber_parent_class)->finalize (obj);
}

/**
     * Transcribes voice messages with the external `whisper` CLI.
     * Results live only in this process: nothing is written back to the
     * message or to disk, so closing Parla forgets every transcription.
     */
static GType
dc_transcriber_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DcTranscriberClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dc_transcriber_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DcTranscriber), 0, (GInstanceInitFunc) dc_transcriber_instance_init, NULL };
	GType dc_transcriber_type_id;
	dc_transcriber_type_id = g_type_register_static (G_TYPE_OBJECT, "DcTranscriber", &g_define_type_info, 0);
	DcTranscriber_private_offset = g_type_add_instance_private (dc_transcriber_type_id, sizeof (DcTranscriberPrivate));
	return dc_transcriber_type_id;
}

GType
dc_transcriber_get_type (void)
{
	static volatile gsize dc_transcriber_type_id__once = 0;
	if (g_once_init_enter (&dc_transcriber_type_id__once)) {
		GType dc_transcriber_type_id;
		dc_transcriber_type_id = dc_transcriber_get_type_once ();
		g_once_init_leave (&dc_transcriber_type_id__once, dc_transcriber_type_id);
	}
	return dc_transcriber_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

