Commit 78900f0d authored by Rudy BARAGLIA's avatar Rudy BARAGLIA

Fixed client

parent 2f5312f1
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 4 11:10:18 2018
......@@ -24,9 +24,7 @@ def main():
with open(args.audioFile, 'rb') as f:
print("Sendind request to transcribe file %s to server at %s" % (args.audioFile, "http://"+SERVER_IP+":"+SERVER_PORT+SERVER_TARGET))
r = requests.post(args.uri, files={'wavFile': f})
print(type(r))
print(r.headers)
print(r.status_code)
print(r.json()['transcript']
if __name__ == '__main__':
main()
\ No newline at end of file
......@@ -171,7 +171,8 @@ class WorkerWebSocketHandler(tornado.websocket.WebSocketHandler):
logging.debug("Message received from worker:" + message)
else:
if 'transcription' in json_msg.keys(): #Receive the file path to process
logging.debug("Response send by worker : %s" % json.dumps({'transcript':json_msg['transcription'].encode('utf-8')}))
response = json.dumps({'transcript':json_msg['transcription'].encode('utf-8')})
logging.debug("Response send by worker : %s" % response)
self.client_handler.receive_response(json.dumps({'transcript':json_msg['transcription']}))
self.client_handler = None
self.application.available_workers.add(self)
......
......@@ -6,6 +6,7 @@ Created on Thu Jan 18 17:32:23 2018
@author: rbaraglia
"""
import sys
import os
from pydub import AudioSegment
......@@ -43,8 +44,9 @@ def average_power_level(sound, chunk_size=100):
input_file is a .wav file path
output_file is a .wav file path
chunk_size in ms
threshold_factor between 0 and 1
threshold_factor ]0,1]
side_effect_accomodation is a number of chunk that will be kept at the beginning and end despite being below the threshold
return the silence segment
'''
def trim_silence_segments(input_file,output_file, chunk_size=100, threshold_factor=0.85, side_effect_accomodation=0):
......@@ -57,7 +59,11 @@ def trim_silence_segments(input_file,output_file, chunk_size=100, threshold_fact
duration = len(sound)
trimmed_sound = sound[start_trim if start_trim - chunk_size*side_effect_accomodation < 0 else start_trim - chunk_size*side_effect_accomodation : duration-end_trim if end_trim + chunk_size*side_effect_accomodation > duration else duration-end_trim + chunk_size*side_effect_accomodation]
trimmed_sound.export(output_file, format="wav")
return (sound[0 : start_trim], sound[len(sound) - end_trim : -1])
if __name__ == '__main__':
trim_silence_segments(sys.argv[1], sys.argv[2])
\ No newline at end of file
[silence1, silence2] = trim_silence_segments(sys.argv[1], sys.argv[2])
# If you want to retrieve silence segment put a path as a third argument .../folder/
if len(sys.argv) == 4:
silence1.export(sys.argv[3] + os.path.basename(sys.argv[1]).split('.')[0] + "beg_sil.wav", format="wav")
silence2.export(sys.argv[3] + os.path.basename(sys.argv[1]).split('.')[0] + "end_sil.wav", format="wav")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment