]> code.delx.au - gnu-emacs-elpa/blob - packages/transcribe/transcribe.el
packages/transcribe.el: Add native discourse analysis in elisp
[gnu-emacs-elpa] / packages / transcribe / transcribe.el
1 ;;; transcribe.el --- Package for audio transcriptions
2
3 ;; Copyright 2014-2015 Free Software Foundation, Inc.
4
5 ;; Author: David Gonzalez Gandara <dggandara@member.fsf.org>
6 ;; Version: 1.0.0
7
8 ;; This program is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12 ;;
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17 ;;
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21 ;;; Commentary:
22
23 ;; REQUIRES:
24 ;; -----------------------------
25 ;; In order to use the audio functions of transcribe, you need to install
26 ;; emms and mpg321.
27 ;;
28 ;; USAGE:
29 ;; -------------------------
30 ;; Transcribe is a tool to make audio transcriptions. It allows the
31 ;; transcriber to control the audio easily while typing, as well as
32 ;; automate the insertion of xml tags, in case the transcription protocol
33 ;; include them.
34 ;; The analyse function will search for a specific structure
35 ;; of episodes that can be automatically added with the macro NewEpisode.
36 ;; The function expects the utterances to be transcribed inside a xml tag
37 ;; with the identifier of the speaker, with the tags <l1> or <l2>, depending
38 ;; on the language used by the person. The attributes expected are the
39 ;; number of clauses that form the utterance and the number of errors the
40 ;; transcriber observes.
41 ;;
42 ;;
43 ;; AUDIO COMMANDS
44 ;; ------------------------------
45 ;; C-x C-p ------> Play audio file. You will be prompted for the name
46 ;; of the file. The recommended format is mp2.
47 ;; <f5> ---------> Pause or play audio.
48 ;; C-x <right> --> seek audio 10 seconds forward.
49 ;; C-x <left> --->seek audio 10 seconds backward.
50 ;; <f8> ---------> seek interactively: positive seconds go forward and
51 ;; negative seconds go backward
52 ;;
53 ;; XML TAGGING COMMANDS
54 ;; --------------------------------------------------
55 ;; C-x C-n --> Create new episode structure. This is useful in case your
56 ;; xml file structure requires it. You can customize the text
57 ;; inserted manipulating the realted function.
58 ;; <f6> -----> Interactively insert new tag. You will be prompted for the
59 ;; content of the tag. The starting tag and the end tag will be
60 ;; inserted automatically and the cursor placed in the proper
61 ;; place to type.
62 ;;
63 ;;
64 ;;
65 ;; SPECIFIC COMMANDS I USE, THAT YOU MAY FIND USEFUL
66 ;; ------------------------------------------------
67 ;; C-x C-a ------> Analyses the text for measurments of performance.
68 ;; <f11> --------> Customised tag 1. Edit the function to adapt to your needs.
69 ;; <f12> --------> Customised tag 2. Edit the function to adapt to your needs.
70 ;; <f7> ---------> Break tag. This command "breaks" a tag in two, that is
71 ;; it inserts an ending tag and then a starting tag.
72 ;; <f4> ---------> Insert atributes. This function insert custom xml attributes.
73 ;; Edit the function to suit you needs.
74
75 ;;; Code:
76
77 (if t (require 'emms-setup))
78 ;(require 'emms-player-mpd)
79 ;(setq emms-player-mpd-server-name "localhost")
80 ;(setq emms-player-mpd-server-port "6600")
81
82 (emms-standard)
83 (emms-default-players)
84 (if t (require 'emms-player-mpg321-remote))
85 (defvar emms-player-list)
86 (push 'emms-player-mpg321-remote emms-player-list)
87
88 (if t (require 'emms-mode-line))
89 (emms-mode-line 1)
90 (if t (require 'emms-playing-time))
91 (emms-playing-time 1)
92
93 (defun transcribe-analyze-episode (episode person)
94 "This calls the external python package analyze_episodes2.py. The new
95 function transcribe-analyze implements its role now."
96 (interactive "sepisode: \nsperson:")
97 (shell-command (concat (expand-file-name "analyze_episodes2.py")
98 " -e " episode " -p " person " -i " buffer-file-name )))
99
100 (defun transcribe-analyze (episodenumber personid)
101 "Extract from a given episode and person the number of asunits per
102 second produced, and the number of clauses per asunits, for L2 and L1."
103 (interactive "sepisodenumber: \nspersonid:")
104 (setq interventionsl2 '())
105 (setq interventionsl1 '())
106 (setq xml (xml-parse-region (point-min) (point-max)))
107 (setq results (car xml))
108 (setq episodes (xml-get-children results 'episode))
109 (setq asunitsl2 0.0000)
110 (setq asunitsl1 0.0000)
111 (setq shifts)
112 (setq clausesl1 0.0000)
113 (setq errorsl1 0.0000)
114 (setq clausesl2 0.0000)
115 (setq errorsl2 0.0000)
116 (dolist (episode episodes)
117 (setq numbernode (xml-get-children episode 'number))
118 (setq number (nth 2 (car numbernode)))
119 (when (equal episodenumber number)
120 (setq durationnode (xml-get-children episode 'duration))
121 (setq duration (nth 2 (car durationnode)))
122 (setq transcription (xml-get-children episode 'transcription))
123 (dolist (turn transcription)
124 (setq interventionnode (xml-get-children turn (intern personid)))
125 (dolist (intervention interventionnode)
126 (setq l2node (xml-get-children intervention 'l2))
127 (dolist (l2turn l2node)
128 (setq l2 (nth 2 l2turn))
129 (setq clausesl2node (nth 1 l2turn))
130 (setq clausesl2nodeinc (cdr (car clausesl2node)))
131 (when (not (equal clausesl2node nil))
132 (setq clausesl2 (+ clausesl2
133 (string-to-number clausesl2nodeinc))))
134 (when (not (equal l2 nil))
135 (add-to-list 'interventionsl2 l2)
136 (setq asunitsl2 (1+ asunitsl2))))
137 (setq l1node (xml-get-children intervention 'l1))
138 (dolist (l1turn l1node)
139 (setq l1 (nth 2 l1turn))
140 (setq clausesl1node (nth 1 l1turn))
141 (setq clausesl1nodeinc (cdr (car clausesl1node)))
142 (when (not (equal clausesl1node nil))
143 (setq clausesl1 (+ clausesl1
144 (string-to-number clausesl1nodeinc))))
145 (when (not (equal l1 nil))
146 (add-to-list 'interventionsl1 l1)
147 (setq asunitsl1 (1+ asunitsl1))))))))
148 (reverse interventionsl2)
149 (reverse interventionsl1)
150 ;(print interventions) ;uncomment to display all the interventions on screen
151 (setq asunitspersecondl2 (/ asunitsl2 (string-to-number duration)))
152 (setq clausesperasunitl2 (/ clausesl2 asunitsl2))
153 (setq asunitspersecondl1 (/ asunitsl1 (string-to-number duration)))
154 (setq clausesperasunitl1 (/ clausesl1 asunitsl1))
155 (princ (format "episode: %s, duration: %s, person: %s\n" number duration personid))
156 (princ (format "L2(Asunits/second): %s, L2(clauses/Asunit): %s, L1(Asunits/second): %s"
157 asunitspersecondl2 clausesperasunitl2 asunitspersecondl1))
158 )
159
160 (defun transcribe-define-xml-tag (xmltag)
161 "This function allows the automatic insetion of a xml tag and places the cursor."
162 (interactive "stag:")
163 (insert (format "<%s></%s>" xmltag xmltag))
164 (backward-char 3)
165 (backward-char (string-width xmltag)))
166
167 (defun transcribe-xml-tag-l1 ()
168 "Inserts a l1 tag and places the cursor"
169 (interactive)
170 (insert "<l1></l1>")
171 (backward-char 3)
172 (backward-char 2))
173
174 (defun transcribe-xml-tag-l2 ()
175 "Inserts a l2 tag and places the cursor"
176 (interactive)
177 (insert "<l2 clauses=\"1\" errors=\"0\"></l2>")
178 (backward-char 3)
179 (backward-char 2))
180
181 (fset 'transcribe-xml-tag-l2-break "</l2><l2 clauses=\"1\" errors=\"0\">")
182 ;inserts a break inside a l2 tag
183 (fset 'transcribe-set-attributes "clauses=\"1\" errors=\"0\"")
184 ;inserts the attributes where they are missing
185
186 (defun transcribe-display-audio-info ()
187 (interactive)
188 (emms-player-mpg321-remote-proc)
189 (shell-command "/usr/bin/mpg321 -R - &"))
190
191
192 (fset 'NewEpisode
193 "<episode>\n<number>DATE-NUMBER</number>\n<duration></duration>\n<comment></comment>\n<subject>Subject (level)</subject>\n<task>\n\t<role>low or high</role>\n<context>low or high</context>\n<demand>low or high</demand>\r</task>\n<auxiliar>Yes/no</auxiliar>\n<transcription>\n</transcription>\n</episode>");Inserts a new episode structure
194
195 ;;;###autoload
196 (define-minor-mode transcribe-mode
197 "Toggle transcribe-mode"
198 nil
199 " Trans"
200 '(([?\C-x ?\C-p] . emms-play-file)
201 ([?\C-x ?\C-a] . transcribe-analyze)
202 ([?\C-x ?\C-n] . NewEpisode)
203 ([?\C-x down] . emms-stop)
204 ([?\C-x right] . emms-seek-forward)
205 ([?\C-x left] . emms-seek-backward)
206 ([f5] . emms-pause)
207 ([f6] . transcribe-define-xml-tag)
208 ([f7] . transcribe-xml-tag-l2-break)
209 ([f8] . emms-seek)
210 ([f4] . transcribe-set-atributes)
211 ([f11] . transcribe-xml-tag-l1)
212 ([f12] . transcribe-xml-tag-l2))
213 )
214
215 (provide 'transcribe)
216
217 ;;; transcribe.el ends here