Example #1
0
def country_model():
    audio_wav = request.data
    mfcc = audio_mfcc(audio_wav)

    # Gender Model
    gender_output, gender_prob = generate_pred(mel=mfcc, model=model_gender,
                                               label=CommonVoiceModels.Gender.OUTPUT,
                                               model_name=CommonVoiceModels.Gender,
                                               )

    return {'Prediction': gender_output, 'Probability': gender_prob}, 201
Example #2
0
    def convert_to_wav(self, index) -> None:
        clips_name = self.label_data.path.values[index]
        path = os.path.join(self.clips_dir, clips_name)
        sample_length_in_seconds = 1

        try:
            signal, _ = librosa.load(path=path, sr=self.SAMPLE_RATE)
            signal, _ = librosa.effects.trim(
                signal, top_db=config.CommonVoiceModels.Frame.FRAME['TOP_DB'])

            duration = len(signal) // self.SAMPLE_RATE

            start = 0
            step = int(sample_length_in_seconds * self.SAMPLE_RATE)

            for i in range(1, duration + 1):
                data = signal[start:start + step]

                training_mfcc = audio_mfcc(data)

                assert training_mfcc.shape[0] == self.model.PARAM["INPUT_SIZE"]
                assert training_mfcc.shape[1] == 13

                clip_name = "{}".format(clips_name.split(".")[0])
                label_name = self.label_data[self.label_data.path ==
                                             clips_name][
                                                 self.data_label].values[0]

                if label_name in config.DO_NOT_INCLUDE:
                    break

                train_test_choice = np.random.choice(
                    ["train_data", "val_data", "test_data"], p=[0.7, 0.2, 0.1])

                dir_path = os.path.join(self.document_path, self.data_label,
                                        train_test_choice)
                check_dir(dir_path)

                dir_path = os.path.join(self.document_path, self.data_label,
                                        train_test_choice, label_name)

                check_dir(dir_path)
                save_path = os.path.join(dir_path, clip_name + "_" + str(i))
                np.save(save_path, training_mfcc.T)
                start = self.SAMPLE_RATE * i
                self.add_count += 1

        except FileNotFoundError:
            _logger.info("Can't find the file {}".format(clips_name))
            self.remove_count += 1

        except FileExistsError:
            _logger.warning("Error in creating folder that's already created")
Example #3
0
def load_audio_wav(audio_wav):
    signal, _ = librosa.load(audio_wav, sr=SAMPLE_RATE)
    mfcc = audio_mfcc(signal)
    return mfcc