Exemplo n.º 1
0
        public void AddAudio(String path, String provider)
        {
            TrainingAudioFile file = new TrainingAudioFile();

            file.RawContent = File.ReadAllBytes(path);
            file.Provider   = provider;

            FFMPEGFileInfo info = FFMPEG.GetFileInfo(path);

            file.AudioFormat       = info.Format;
            file.AudioSamplingRate = info.SamplingRate;
            file.AudioBitrateInKB  = (int)info.BitRate;

            AudioFiles.Add(file);
        }
Exemplo n.º 2
0
        private void SaveNewAudioFile(TrainingAudioFile file, TrainingEntry entry, int index)
        {
            SQLiteCommand command = new SQLiteCommand();

            command.CommandText = $"INSERT INTO audio_files(file_name, format, sampling_rate, bit_rate, entry_id, provider) VALUES(@file_name, {(int)file.AudioFormat}, {file.AudioSamplingRate}, {file.AudioBitrateInKB}, {entry.ID}, @provider)";
            command.Connection  = _connection;

            String fileName = $"{entry.ID}_{index}.{GetExtension(file.AudioFormat)}";

            command.Parameters.AddWithValue("@file_name", fileName);
            command.Parameters.AddWithValue("@provider", file.Provider);

            command.ExecuteNonQuery();

            File.WriteAllBytes(GetAudioDirectory() + fileName, file.RawContent);

            file.ID = -1;
        }
Exemplo n.º 3
0
        private void LoadAudioFileInfo()
        {
            SQLiteCommand    command            = new SQLiteCommand("SELECT * FROM audio_files", _connection);
            SQLiteDataReader reader             = command.ExecuteReader();
            String           baseAudioDirectory = GetAudioDirectory();

            while (reader.Read())
            {
                TrainingAudioFile entry = new TrainingAudioFile();

                entry.ID                = Convert.ToInt32(reader["id"]);
                entry.FilePath          = baseAudioDirectory + Convert.ToString(reader["file_name"]);
                entry.AudioFormat       = (AudioFormat)Convert.ToInt32(reader["format"]);
                entry.AudioBitrateInKB  = Convert.ToInt32(reader["bit_rate"]);
                entry.AudioSamplingRate = Convert.ToInt32(reader["sampling_rate"]);

                int entryID = Convert.ToInt32(reader["entry_id"]);

                _entriesIDIndex[entryID].AudioFiles.Add(entry);
            }

            reader.Close();
        }