4

안녕 개발자에서 녹음 된 오디오,문제 동안, 우리는 MP3 파일로 녹음 된 음성을 저장하면 WP7

. Windows Media Player가 파일을 재생할 수 없으므로 파일을 여는 동안 오류가 발생합니다. 플레이어가 파일 형식을 지원하지 않거나 파일 압축에 사용 된 코덱을 지원하지 않을 수 있습니다.

내 소스 코드

namespace Windows_Phone_Audio_Recorder 
{ 
    public partial class MainPage : PhoneApplicationPage 
    { 
     MemoryStream m_msAudio = new MemoryStream(); 
     Microphone m_micDevice = Microphone.Default; 
     byte[] m_baBuffer; 
     SoundEffect m_sePlayBack; 
     ViewModel vm = new ViewModel(); 
     long m_lDuration = 0; 
     bool m_bStart = false; 
     bool m_bPlay = false; 
     private DispatcherTimer m_dispatcherTimer; 

     public MainPage() 
     { 
      InitializeComponent(); 

      SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;    
      DataContext = vm; 
      m_dispatcherTimer = new DispatcherTimer(); 

      m_dispatcherTimer.Interval = TimeSpan.FromTicks(10000); 

      m_dispatcherTimer.Tick += frameworkDispatcherTimer_Tick; 
      m_dispatcherTimer.Start(); 
      FrameworkDispatcher.Update();   
      //icBar.ItemsSource = vm.AudioData; 
     } 

     void frameworkDispatcherTimer_Tick(object sender, EventArgs e) 
     { 
      FrameworkDispatcher.Update(); 
     }   

     private void btnStart_Click(object sender, RoutedEventArgs e) 
     { 
      m_bStart = true; 
      tbData.Text = "00:00:00"; 
      m_lDuration = 0; 
      m_micDevice.BufferDuration = TimeSpan.FromMilliseconds(1000); 
      m_baBuffer = new byte[m_micDevice.GetSampleSizeInBytes(m_micDevice.BufferDuration)]; 
      //m_micDevice.BufferReady += new EventHandler(m_Microphone_BufferReady); 
      m_micDevice.BufferReady += new EventHandler<EventArgs>(m_Microphone_BufferReady); 
      m_micDevice.Start(); 
     } 

     void m_Microphone_BufferReady(object sender, EventArgs e) 
     { 
      m_micDevice.GetData(m_baBuffer); 
       Dispatcher.BeginInvoke(()=> 
       { 
        vm.LoadAudioData(m_baBuffer); 
        m_lDuration++; 
        TimeSpan tsTemp = new TimeSpan(m_lDuration * 10000000); 
        tbData.Text = tsTemp.Hours.ToString().PadLeft(2, '0') + ":" + tsTemp.Minutes.ToString().PadLeft(2, '0') + ":" + tsTemp.Seconds.ToString().PadLeft(2, '0'); 
       } 
       ); 
      //this.Dispatcher.BeginInvoke(new Action(() => vm.LoadAudioData(m_baBuffer))); 
      //this.Dispatcher.BeginInvoke(new Action(() => tbData.Text = m_baBuffer[0].ToString() + m_baBuffer[1].ToString() + m_baBuffer[2].ToString() + m_baBuffer[3].ToString())); 
      m_msAudio.Write(m_baBuffer,0, m_baBuffer.Length); 
     } 

     private void btnStop_Click(object sender, RoutedEventArgs e) 
     { 
      if (m_bStart) 
      { 
       m_bStart = false; 
       m_micDevice.Stop(); 
       ProgressPopup.IsOpen = true; 
      } 

      if (m_bPlay) 
      { 
       m_bPlay = false; 
       m_sePlayBack.Dispose(); 
      } 
     } 

     private void btnPlay_Click(object sender, RoutedEventArgs e) 
     { 
      m_bPlay = true; 
      m_sePlayBack = new SoundEffect(m_msAudio.ToArray(), m_micDevice.SampleRate, AudioChannels.Mono); 
      m_sePlayBack.Play(); 
     } 

     private void btnSave_Click(object sender, RoutedEventArgs e) 
     { 
      if (txtAudio.Text != "") 
      { 
       IsolatedStorageFile isfData = IsolatedStorageFile.GetUserStoreForApplication(); 
       string strSource = txtAudio.Text + ".wav"; 
       int nIndex = 0; 
       while (isfData.FileExists(txtAudio.Text)) 
       { 
        strSource = txtAudio.Text + nIndex.ToString().PadLeft(2, '0') + ".wav"; 
       } 

       IsolatedStorageFileStream isfStream = new IsolatedStorageFileStream(strSource, FileMode.Create, IsolatedStorageFile.GetUserStoreForApplication()); 
       isfStream.Write(m_msAudio.ToArray(), 0, m_msAudio.ToArray().Length); 
       isfStream.Close(); 
      } 
      this.Dispatcher.BeginInvoke(new Action(() => ProgressPopup.IsOpen = false));   
     } 
    } 
} 

DOTNET Weblineindia

내 소스 코드 여기를

입니다 ....이 문제를 극복 할 수있는 솔루션을주지하시기 바랍니다 PHP 서버에 오디오 업로드하기 :

public void UploadAudio() 
    { 
     try 
     { 
      if (m_msAudio != null) 
      { 
       var fileUploadUrl = "uploadurl"; 

       var client = new HttpClient(); 
       m_msAudio.Position = 0; 
       MultipartFormDataContent content = new MultipartFormDataContent(); 

       content.Add(new StreamContent(m_msAudio), "uploaded_file", strFileName); 

       // upload the file sending the form info and ensure a result.it will throw an exception if the service doesn't return a valid successful status code 

       client.PostAsync(fileUploadUrl, content) 

       .ContinueWith((postTask) => 
       { 
        try 
        { 
         postTask.Result.EnsureSuccessStatusCode(); 
         var respo = postTask.Result.Content.ReadAsStringAsync(); 
         string[] splitChar = respo.Result.Split('"'); 
         FilePath = splitChar[3].ToString(); 
         Dispatcher.BeginInvoke(() => NavigationService.Navigate(new Uri("/VoiceSlider.xaml?FName=" + strFileName, UriKind.Relative)));       
        } 
        catch (Exception ex) 
        { 
         // Logger.Log.WriteToLogger(ex.Message); 
         MessageBox.Show("voice not uploaded" + ex.Message); 
        } 

       }); 
      } 
     } 
     catch (Exception ex) 
     { 
      //Logger.Log.WriteToLogger(ex.Message + "Error occured while uploading image to server"); 
     } 
    } 

답변

1

우선 Windows Phone에서는 .mp3 파일을 기록 할 수 없습니다. 따라서 저장중인 .mp3 파일은 Windows Phone Player에서 재생되지 않습니다.

this.에서 보겠습니다.이 데모는 .wav 파일을 기록 할 때 잘 작동합니다.

.aac, .amr과 같은 다른 형식을 저장하려면 사용자 AudioVideoCaptureDevice 클래스를 저장하십시오.

+0

안녕하세요, DotNet Weblineindia 예, 답변을 수락합니다. 녹음 된 wav 파일을 PHP 서버에 업로드하는 방법은 무엇입니까? –

+1

안녕하세요, 당신은 서버에서 multipart webservice를 만들고 장치에서 사운드의 바이트 데이터를 업로드해야합니다. 서버 측에서 해당 데이터를받은 다음 서버에 .wav 파일로 저장하십시오. –

+0

DotNet Weblineindia, OK 저장 된 저장 공간에 저장하면 서버에 업로드해도 MP3 파일이 재생되지 않습니다. 여기에서 시도했습니다. 죄송합니다. 코드를 복사 할 수 없으며 댓글 페이지에 표시 할 수 없습니다. 게시 됨 답변 소스로 PHP 서버에 오디오를 업로드하기위한 소스 코드 Plz 그것을 확인하고 회신 .... –

관련 문제