RAPP Platform  v0.6.0
RAPP Platform is a collection of ROS nodes and back-end processes that aim to deliver ready-to-use generic services to robots
 All Classes Namespaces Files Functions Variables Macros
rapp_sox_denoise.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- encode: utf-8 -*-
3 
4 #Copyright 2015 RAPP
5 
6 #Licensed under the Apache License, Version 2.0 (the "License");
7 #you may not use this file except in compliance with the License.
8 #You may obtain a copy of the License at
9 
10  #http://www.apache.org/licenses/LICENSE-2.0
11 
12 #Unless required by applicable law or agreed to in writing, software
13 #distributed under the License is distributed on an "AS IS" BASIS,
14 #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #See the License for the specific language governing permissions and
16 #limitations under the License.
17 
18 # Authors: Manos Tsardoulias
19 # contact: etsardou@iti.gr
20 
21 import sys
22 import time
23 import os
24 from pylab import *
25 from scipy.io import wavfile
26 
27 ## @class SoxDenoise
28 # Performs denoising on an audio file employing Sox application
29 class SoxDenoise :
30 
31  ## Performs denoising employing Sox apllication
32  #
33  # Handles service callback
34  # rapp_audio_processing.AudioProcessing#denoiseCallback
35  #
36  # @param user [string] The system user, for environmental variable access
37  # @param audio_file [string] Audio file path
38  # @param audio_type [string] Audio file's type
39  # @param denoised_audio_file [string] Path to write denoised audio file
40  # @param scale [float] Energy denoise scale
41  def soxDenoise(self, user, audio_type, audio_file, denoised_audio_file, scale):
42  if not os.path.isfile(audio_file):
43  return "The audio file does not exist"
44 
45  if scale < 0 or scale > 1:
46  return "Invalid scale. Scale must be between [0,1]"
47 
48  if ".wav" not in audio_file:
49  return "The file for denoising is not wav"
50  samp_freq, signal = wavfile.read(audio_file)
51  if len(signal.shape) != 1:
52  return "The file for denoising has not 1 channel"
53 
54 
55  directory = os.path.expanduser("~/rapp_platform_files/audio_processing/") + user
56  noise_profile = directory + "/noise_profile/noise_profile_" + audio_type
57 
58  if not os.path.isfile(noise_profile):
59  return "No noise profile for the " + audio_type + " type exists"
60 
61  command = "sox " + audio_file + " " + denoised_audio_file +\
62  " noisered " + noise_profile + " " + str(scale)
63  com_res = os.system(command)
64 
65  if com_res != 0:
66  return "System sox malfunctioned"
67  else:
68  return "true"
69 
def soxDenoise
Performs denoising employing Sox apllication.
Performs denoising on an audio file employing Sox application.