25 from scipy.io
import wavfile
27 from rapp_utilities
import Utilities
48 directory = os.path.expanduser(
"~/rapp_platform_files/audio_processing/") + user
49 if not os.path.isdir(directory):
50 os.makedirs(directory)
51 com_res = os.system(
"chmod 777 " + directory)
53 return "Error: Server chmod malfunctioned"
55 directory +=
"/noise_profile/"
56 if not os.path.isdir(directory):
57 os.makedirs(directory)
58 com_res = os.system(
"chmod 777 " + directory)
60 return "Error: Server chmod malfunctioned"
62 noise_profile_file = directory
63 new_audio = noise_audio_file
65 if not os.path.isfile(new_audio):
66 return "Error: The audio file does not exist"
69 if audio_file_type ==
'nao_ogg':
70 if ".ogg" not in new_audio:
71 return "Error: ogg type selected but file is of another type"
73 com_res = os.system(
"sox " + noise_audio_file +
" " + new_audio)
75 return "Error: Server sox malfunctioned"
76 cleanup.append(new_audio)
78 elif audio_file_type ==
"nao_wav_1_ch":
79 if ".wav" not in new_audio:
80 return "Error: wav type 1 channel selected but file is of another type"
81 samp_freq, signal = wavfile.read(new_audio)
82 if len(signal.shape) != 1:
83 return "Error: wav 1 ch declared but the audio file has " +\
84 str(signal.shape[1]) +
' channels'
87 elif audio_file_type ==
"nao_wav_4_ch":
88 if ".wav" not in new_audio:
89 return "Error: wav type 4 channels selected but file is of another type"
90 samp_freq, signal = wavfile.read(new_audio)
91 if len(signal.shape) != 2
or signal.shape[1] != 4:
92 return "Error: wav 4 ch declared but the audio file has not 4 channels"
93 new_audio +=
"_1ch.wav"
94 com_res = os.system(
"sox " + noise_audio_file +
" -c 1 -r 16000 " + \
97 return "Error: Server sox malfunctioned"
98 cleanup.append(new_audio)
101 success =
"Non valid noise audio type"
102 status = self.utilities.cleanup(cleanup)
104 success +=
" " + status
107 noise_profile_uri = directory +
"/noise_profile_" + audio_file_type
109 com_res = os.system(\
110 "sox " + new_audio +
" -t null /dev/null trim 0.5 2.5 noiseprof "\
113 return "Error: Server sox malfunctioned"
115 com_res = os.system(
"chmod 777 " + noise_profile_uri)
117 return "Error: Server chmod malfunctioned"
119 status = self.utilities.cleanup(cleanup)
Evaluates the noise profile for an audio file.
def __init__
Performs initializations.
def setNoise_profile
Evaluates the audio profile.