20 praat = subprocess.Popen([DBConstants.SETTINGS.PRAAT_PATH])
28 PraatInterop.send_commands([
'Quit'])
41 DBConstants.SETTINGS.SENDPRAAT_PATH,
45 if platform.system().lower() !=
'windows':
46 sendpraat_args.insert(1,
'0')
48 return subprocess.call(sendpraat_args,
63 'Open long sound file... %s' % (wav_filename),
64 'Extract part... %f %f yes' % (start_time, end_time),
68 script += [
'View & Edit']
75 port = int(DBConstants.SETTINGS.PRAAT_IPC_PORT)
76 sound_ed_name = os.path.basename(wav_filename)[:-4]
79 'editor Sound %s' % (sound_ed_name),
80 'start = Get start of selection',
81 'end = Get end of selection',
83 "sendsocket localhost:%d 'start' 'end'" % (port),
93 'snd = selected("Sound")',
94 'To Pitch... 0.01 60 700',
95 'q1 = Get quantile... 0 0 0.25 Hertz',
96 'q3 = Get quantile... 0 0 0.75 Hertz',
101 'if q1 != undefined',
102 ' floor = q1 * 0.75',
104 'if q3 != undefined',
105 ' ceiling = q3 * 2.0',
107 'pitch = To Pitch... 0.001 floor ceiling',
117 "Extract part... %f %f yes" % (start_time, stop_time),
118 "Filter (pass Hann band)... %d %d %d" % (filter_from, filter_to, filter_smoothing),
119 "max = Get maximum... 0 0 Sinc70",
120 "min = Get minimum... 0 0 Sinc70",
121 "max_intensity = max(abs(min), abs(max))",
122 "scale_factor = 0.999 / max_intensity",
123 "Multiply... scale_factor",
124 'Save as WAV file... %s' % (clip_filename),
125 'select Sound %s' % (file_code +
'_band'),
127 'select Sound %s' % (file_code),
129 'select LongSound %s' % (file_code),
137 port = int(DBConstants.SETTINGS.PRAAT_IPC_PORT)
138 pitch_ed_name = os.path.basename(wav_filename)[:-4]
142 "editor Pitch %s" % (pitch_ed_name),
143 "start = %f" % (clip_start),
144 "end = %f" % (clip_end),
145 "start_pitch = undefined",
146 "start_time = undefined",
147 "end_pitch = undefined",
148 "end_time = undefined",
149 "sample_time = start",
150 "while start_pitch == undefined and sample_time <= end",
151 " Move cursor to... 'sample_time'",
152 " pitch = Get pitch",
153 " if pitch != undefined",
154 " start_pitch = pitch",
155 " start_time = sample_time",
157 " sample_time = sample_time + %f" % (step),
160 "while end_pitch == undefined and sample_time >= start",
161 " Move cursor to... 'sample_time'",
162 " pitch = Get pitch",
163 " if pitch != undefined",
164 " end_pitch = pitch",
165 " end_time = sample_time",
167 " sample_time = sample_time - %f" % (step),
170 "sendsocket localhost:%d 'start_time' 'start_pitch' 'end_time' 'end_pitch'" % (port),
179 port = int(DBConstants.SETTINGS.PRAAT_IPC_PORT)
182 'min_pitch = Get minimum... 0.0 0.0 Hertz Parabolic',
183 'max_pitch = Get maximum... 0.0 0.0 Hertz Parabolic',
184 'mean_pitch = Get mean... 0.0 0.0 Hertz',
185 "sendsocket localhost:%d 'min_pitch' 'max_pitch' 'mean_pitch'" % (port),
196 port = int(DBConstants.SETTINGS.PRAAT_IPC_PORT)
199 serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
200 serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
201 serversocket.setblocking(0)
203 serversocket.bind((
'localhost', port))
205 serversocket.listen(1)
215 select.select([serversocket], [], [], 20)
217 (clientsocket, address) = serversocket.accept()
218 c = clientsocket.recv(1)
222 c = clientsocket.recv(1)
225 return msg.split(delim)