コード例 #1
0
ファイル: WAVFileHandler.cs プロジェクト: sbeleidy/PEERbots
 //**************************//
 //*** SENDING AUDIO CLIP ***//
 //**************************//
 public void SendAudioFromClip(AudioClip audioClip)
 {
     if (audioClip == null)
     {
         return;
     }
     byte[] bytes = OpenWavParser.AudioClipToByteArray(audioClip);
     SendAudioFromBytes(bytes);
 }
コード例 #2
0
    //using OpenWavParser from the Unity asset store. // You can make your own wav parser
    public void SaveFile()
    {
        string totalpath = Application.persistentDataPath + "/VoiceRecording" + "/" + newfilename;

        byte[] wavFile = OpenWavParser.AudioClipToByteArray(myrecording.clip);
        try
        {
            File.WriteAllBytes(Application.persistentDataPath + "/VoiceRecording" + "/" + newfilename, wavFile);
            File.Exists("totalpath");
        }

        catch (Exception e)
        {
            Debug.Log("error writing" + e);
        }
        myrecording.enabled = true;
    }
コード例 #3
0
 //--- Save Audio ---//
 //requests.post('http://'+self.ip+'/api/audio',json={"FileName": "tts.wav", "Data": "34,88,90,49,56,...", "ImmediatelyApply": True, "OverwriteExisting": True})
 public void SaveAudio(string filename, bool ImmediatelyApply = true, bool OverwriteExisting = true)
 {
     audioname = filename;
     //Mac & compatibility method: directly stream AudioClip to target
     if (isMacOrCompatiblityVoice())
     {
         byte[] bytes        = OpenWavParser.AudioClipToByteArray(audiosource.clip);
         string base64String = Convert.ToBase64String(bytes);
         //Save data as text to see
         StreamWriter writer = new StreamWriter(audiopath + "tts.txt", false); //true to append, false to overwrite
         writer.WriteLine(base64String);
         writer.Close();
         //Send it over!
         if (!string.IsNullOrEmpty(filename) && !string.IsNullOrEmpty(base64String))
         {
             Debug.Log("[Here] Filename: " + filename + " | base64string: " + base64String);
             StartCoroutine(_SaveAudio(filename, base64String, ImmediatelyApply, OverwriteExisting));
         }
         else
         {
             Debug.LogWarning("Null base64string! Cannot save audio.");
         }
     }
     //Android/Win/Linux method: save TTS first as WAV and then stream to target
     else
     {
         string path         = audiopath + "tts" + ".wav"; //Speaker.AudioFileExtension;
         byte[] bytes        = File.ReadAllBytes(path);
         string base64String = Convert.ToBase64String(bytes);
         //Save data as text to see
         StreamWriter writer = new StreamWriter(audiopath + "tts.txt", false); //true to append, false to overwrite
         writer.WriteLine(base64String);
         writer.Close();
         //Send it over!
         if (!string.IsNullOrEmpty(filename) && !string.IsNullOrEmpty(base64String))
         {
             StartCoroutine(_SaveAudio(filename, base64String, ImmediatelyApply, OverwriteExisting));
         }
         else
         {
             Debug.LogWarning("Null base64string! Cannot save audio.");
         }
     }
 }
コード例 #4
0
 public void SaveClip()
 {
     byte[] wavFile = OpenWavParser.AudioClipToByteArray(source.clip);
     File.WriteAllBytes(Application.persistentDataPath + "/MyFile.wav", wavFile);
 }