public async Task <long> SaveAudioFileAsync(Stream fileStream, FCMomentAudioFileInfo fileInfo)
        {
            var audioFile = new LabelingAudio
            {
                FileName = Guid.NewGuid().ToString("N")
            };

            if (await CheckIfFileExist(audioFile.FileName))
            {
                return(0);
            }

            using (var wavFileStream = CreateMemoryStream(fileStream))
            {
                audioFile.AudioDuration = GetAudioDuration(wavFileStream);

                if (audioFile.AudioDuration.TotalSeconds == 0)
                {
                    return(0);
                }

                await SaveAudioFileToLocalFolder(wavFileStream, audioFile.FileName, fileInfo.ImportNumber);
            }


            audioFile.CallId   = fileInfo.CallId;
            audioFile.FilePath = GenerateFilePath(audioFile.FileName, fileInfo.ImportNumber);
            await labelingAudioRepository.AddAsync(audioFile);

            return(audioFile.Id);
        }
        public async Task <long> SaveAudioFileAsync(MemoryStream stream, string boundary, long instanceId, long campaignId)
        {
            MultipartSection section;
            var audioFile = new LabelingAudio();

            stream.Position = 0;
            var reader = new MultipartReader(boundary, stream);

            while ((section = await reader.ReadNextSectionAsync()) != null)
            {
                if (section.HasHeaderInfo("file"))
                {
                    ContentDisposition contentDisposition = new ContentDisposition(section.ContentDisposition);
                    audioFile.FileName = contentDisposition.FileName.Remove(contentDisposition.FileName.Length - 4);

                    if (await CheckIfFileExist(audioFile.FileName, instanceId, campaignId))
                    {
                        return(0);
                    }
                }
                if (section.HasHeaderFile() && !string.IsNullOrEmpty(audioFile.FileName))
                {
                    using (var wavFileStream = CreateMemoryStream(section.Body))
                    {
                        audioFile.AudioDuration = GetAudioDuration(wavFileStream);

                        if (audioFile.AudioDuration.TotalSeconds == 0)
                        {
                            return(0);
                        }

                        await SaveAudioFileToLocalFolder(wavFileStream, audioFile.FileName, instanceId, campaignId);
                    }
                }
            }
            audioFile.CampaignId = campaignId;
            audioFile.InstanceId = instanceId;
            audioFile.FilePath   = GenerateFilePath(audioFile.FileName, instanceId, campaignId);
            await labelingAudioRepository.AddAsync(audioFile);

            return(audioFile.Id);
        }
Beispiel #3
0
 public Task AddAsync(LabelingAudio audio)
 {
     labelingAudioDataSet.Add(audio);
     return(dbContext.SaveChangesAsync());
 }