gaurav-gireesh commented on a change in pull request #13241: [MXNET-1210 ][WIP] 
Gluon Audio
URL: https://github.com/apache/incubator-mxnet/pull/13241#discussion_r233315405
 
 

 ##########
 File path: python/mxnet/gluon/contrib/data/audio/transforms.py
 ##########
 @@ -0,0 +1,183 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# coding: utf-8
+# pylint: disable= arguments-differ
+"Audio transforms."
+
+import numpy as np
+import librosa
+import mxnet as mx
+from mxnet import nd
+from mxnet.gluon.block import Block
+
+
+class Loader(Block):
+    """
+        This transform opens a filepath and converts that into an NDArray 
using librosa to load
+    """
+    def __init__(self, **kwargs):
+        super(Loader, self).__init__(**kwargs)
+
+    def forward(self, x):
+        if not librosa:
+            raise RuntimeError("Librosa dependency is not installed! Install 
that and retry!")
+        X1, _ = librosa.load(x, res_type='kaiser_fast')
+        return nd.array(X1)
+
+
+class MFCC(Block):
+    """
+        Extracts Mel frequency cepstrum coefficients from the audio data file
+        More details : 
https://librosa.github.io/librosa/generated/librosa.feature.mfcc.html
+
+        returns:    An NDArray after extracting mfcc features from the input
+    """
+    def __init__(self, **kwargs):
+        super(MFCC, self).__init__(**kwargs)
+
+    def forward(self, x):
+        if not librosa:
+            raise RuntimeError("Librosa dependency is not installed! Install 
that and retry")
+
+        audio_tmp = np.mean(librosa.feature.mfcc(y=x.asnumpy(), sr=22050, 
n_mfcc=40).T, axis=0)
 
 Review comment:
   Yes, addressed this. Thanks

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to