1 ;;; transcribe.el --- Package for audio transcriptions
3 ;; Copyright 2014-2015 Free Software Foundation, Inc.
5 ;; Author: David Gonzalez Gandara <dggandara@member.fsf.org>
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.
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.
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/>.
24 ;; -----------------------------
25 ;; In order to use the audio functions of transcribe, you need to install
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
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.
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
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
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.
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")
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)
88 (if t (require 'emms-mode-line))
90 (if t (require 'emms-playing-time))
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 )))
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)))
108 (episodes (xml-get-children results 'episode))
119 (dolist (episode episodes)
120 (let*((numbernode (xml-get-children episode 'number)))
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)))
127 (setq duration (nth 2 (car durationnode)))
128 (dolist (turn transcription)
129 (let* ((interventionnode (xml-get-children turn
132 (dolist (intervention interventionnode)
133 (let* ((l2node (xml-get-children intervention 'l2))
134 (l1node (xml-get-children intervention 'l1)))
136 (dolist (l2turn l2node)
137 (let* ((l2 (nth 2 l2turn))
138 (clausesl2node (nth 1 l2turn))
139 (clausesl2nodeinc (cdr (car clausesl2node))))
141 (when (not (equal clausesl2node nil))
142 (setq clausesl2 (+ clausesl2 (string-to-number
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))))
152 (when (not (equal clausesl1node nil))
153 (setq clausesl1 (+ clausesl1 (string-to-number
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 (let((asunitspersecondl2 (/ asunitsl2 (string-to-number duration)))
162 (clausesperasunitl2 (/ clausesl2 asunitsl2))
163 (asunitspersecondl1 (/ asunitsl1 (string-to-number duration)))
164 (clausesperasunitl1 (/ clausesl1 asunitsl1)))
166 (princ (format "episode: %s, duration: %s, person: %s\n" episodenumber duration personid))
167 (princ (format "L2(Asunits/second): %s, L2(clauses/Asunit): %s, L1(Asunits/second): %s"
168 asunitspersecondl2 clausesperasunitl2 asunitspersecondl1)))))
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))
175 (backward-char (string-width xmltag)))
177 (defun transcribe-xml-tag-l1 ()
178 "Inserts a l1 tag and places the cursor"
184 (defun transcribe-xml-tag-l2 ()
185 "Inserts a l2 tag and places the cursor"
187 (insert "<l2 clauses=\"1\" errors=\"0\"></l2>")
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
196 (defun transcribe-display-audio-info ()
198 (emms-player-mpg321-remote-proc)
199 (shell-command "/usr/bin/mpg321 -R - &"))
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
206 (define-minor-mode transcribe-mode
207 "Toggle transcribe-mode"
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)
217 ([f6] . transcribe-define-xml-tag)
218 ([f7] . transcribe-xml-tag-l2-break)
220 ([f4] . transcribe-set-atributes)
221 ([f11] . transcribe-xml-tag-l1)
222 ([f12] . transcribe-xml-tag-l2))
225 (provide 'transcribe)
227 ;;; transcribe.el ends here