]> code.delx.au - gnu-emacs-elpa/blob - packages/transcribe/transcribe.el
/packages/transcribe: Fix variables
[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.1
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 (let* ((interventionsl2 '())
105 (interventionsl1 '())
106 (xml (xml-parse-region (point-min) (point-max)))
107 (results (car xml))
108 (episodes (xml-get-children results 'episode))
109 (asunitsl2 0.0000)
110 (asunitsl1 0.0000)
111 (shifts nil)
112 (clausesl1 0.0000)
113 (errorsl1 0.0000)
114 (clausesl2 0.0000)
115 (errorsl2 0.0000)
116 (duration nil)
117 (number nil))
118
119 (dolist (episode episodes)
120 (let*((numbernode (xml-get-children episode 'number)))
121
122 (setq number (nth 2 (car numbernode)))
123 (when (equal episodenumber number)
124 (let* ((durationnode (xml-get-children episode 'duration))
125 (transcription (xml-get-children episode 'transcription)))
126
127 (setq duration (nth 2 (car durationnode)))
128 (dolist (turn transcription)
129 (let* ((interventionnode (xml-get-children turn
130 (intern personid))))
131
132 (dolist (intervention interventionnode)
133 (let* ((l2node (xml-get-children intervention 'l2))
134 (l1node (xml-get-children intervention 'l1)))
135
136 (dolist (l2turn l2node)
137 (let* ((l2 (nth 2 l2turn))
138 (clausesl2node (nth 1 l2turn))
139 (clausesl2nodeinc (cdr (car clausesl2node))))
140
141 (when (not (equal clausesl2node nil))
142 (setq clausesl2 (+ clausesl2 (string-to-number
143 clausesl2nodeinc))))
144 (when (not (equal l2 nil))
145 (add-to-list 'interventionsl2 l2)
146 (setq asunitsl2 (1+ asunitsl2)))))
147 (dolist (l1turn l1node)
148 (let*((l1 (nth 2 l1turn))
149 (clausesl1node (nth 1 l1turn))
150 (clausesl1nodeinc (cdr (car clausesl1node))))
151
152 (when (not (equal clausesl1node nil))
153 (setq clausesl1 (+ clausesl1 (string-to-number
154 clausesl1nodeinc))))
155 (when (not (equal l1 nil))
156 (add-to-list 'interventionsl1 l1)
157 (setq asunitsl1 (1+ asunitsl1)))))))))))))
158 (reverse interventionsl2)
159 (reverse interventionsl1)
160 ;(print interventions) ;uncomment to display all the interventions on screen
161 (setq asunitspersecondl2 (/ asunitsl2 (string-to-number duration)))
162 (setq clausesperasunitl2 (/ clausesl2 asunitsl2))
163 (setq asunitspersecondl1 (/ asunitsl1 (string-to-number duration)))
164 (setq clausesperasunitl1 (/ clausesl1 asunitsl1))
165 (princ (format "episode: %s, duration: %s, person: %s\n" number duration personid))
166 (princ (format "L2(Asunits/second): %s, L2(clauses/Asunit): %s, L1(Asunits/second): %s"
167 asunitspersecondl2 clausesperasunitl2 asunitspersecondl1)))
168 )
169
170 (defun transcribe-define-xml-tag (xmltag)
171 "This function allows the automatic insetion of a xml tag and places the cursor."
172 (interactive "stag:")
173 (insert (format "<%s></%s>" xmltag xmltag))
174 (backward-char 3)
175 (backward-char (string-width xmltag)))
176
177 (defun transcribe-xml-tag-l1 ()
178 "Inserts a l1 tag and places the cursor"
179 (interactive)
180 (insert "<l1></l1>")
181 (backward-char 3)
182 (backward-char 2))
183
184 (defun transcribe-xml-tag-l2 ()
185 "Inserts a l2 tag and places the cursor"
186 (interactive)
187 (insert "<l2 clauses=\"1\" errors=\"0\"></l2>")
188 (backward-char 3)
189 (backward-char 2))
190
191 (fset 'transcribe-xml-tag-l2-break "</l2><l2 clauses=\"1\" errors=\"0\">")
192 ;inserts a break inside a l2 tag
193 (fset 'transcribe-set-attributes "clauses=\"1\" errors=\"0\"")
194 ;inserts the attributes where they are missing
195
196 (defun transcribe-display-audio-info ()
197 (interactive)
198 (emms-player-mpg321-remote-proc)
199 (shell-command "/usr/bin/mpg321 -R - &"))
200
201
202 (fset 'NewEpisode
203 "<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
204
205 ;;;###autoload
206 (define-minor-mode transcribe-mode
207 "Toggle transcribe-mode"
208 nil
209 " Trans"
210 '(([?\C-x ?\C-p] . emms-play-file)
211 ([?\C-x ?\C-a] . transcribe-analyze)
212 ([?\C-x ?\C-n] . NewEpisode)
213 ([?\C-x down] . emms-stop)
214 ([?\C-x right] . emms-seek-forward)
215 ([?\C-x left] . emms-seek-backward)
216 ([f5] . emms-pause)
217 ([f6] . transcribe-define-xml-tag)
218 ([f7] . transcribe-xml-tag-l2-break)
219 ([f8] . emms-seek)
220 ([f4] . transcribe-set-atributes)
221 ([f11] . transcribe-xml-tag-l1)
222 ([f12] . transcribe-xml-tag-l2))
223 )
224
225 (provide 'transcribe)
226
227 ;;; transcribe.el ends here