示例#1
0
    public AudioClip ParseAudioFromBytes(byte[] bytes)
    {
        AudioClip audioClip = OpenWavParser.ByteArrayToAudioClip(bytes);

        OnAudioClipParsed(audioClip);
        return(audioClip);
    }
示例#2
0
 //**************************//
 //*** SENDING AUDIO CLIP ***//
 //**************************//
 public void SendAudioFromClip(AudioClip audioClip)
 {
     if (audioClip == null)
     {
         return;
     }
     byte[] bytes = OpenWavParser.AudioClipToByteArray(audioClip);
     SendAudioFromBytes(bytes);
 }
示例#3
0
    public void PlayAudioFromBytes(byte[] bytes)
    {
        if (bytes == null || bytes.Length == 0)
        {
            Debug.LogWarning("Cannot play audio from null or empty bytes!"); return;
        }
        AudioClip audioClip = OpenWavParser.ByteArrayToAudioClip(bytes);

        if (audioSource != null)
        {
            audioSource.clip = audioClip; audioSource.Play();
        }
    }
示例#4
0
 public void LoadCustomFile()
 {
     if (File.Exists(inputFile.text))
     {
         byte[] wavFile = File.ReadAllBytes(inputFile.text);
         source.clip      = OpenWavParser.ByteArrayToAudioClip(wavFile);
         loadDisplay.text = "Samples: " + source.clip.samples.ToString();
     }
     else
     {
         loadDisplay.text = "File not found";
     }
 }
示例#5
0
    public void LoadDefaultFile()
    {
        string filePath = Application.persistentDataPath + "/MyFile.wav";

        if (File.Exists(filePath))
        {
            byte[] wavFile = File.ReadAllBytes(filePath);
            source.clip      = OpenWavParser.ByteArrayToAudioClip(wavFile);
            loadDisplay.text = "Samples: " + source.clip.samples.ToString();
        }
        else
        {
            loadDisplay.text = "File not found";
        }
    }
    //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;
    }
示例#7
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.");
         }
     }
 }
示例#8
0
    private void PlayAudio()
    {
        Text.text = "PLaying";
        if (File.Exists(path))
        {
            byte[] wavFile = File.ReadAllBytes(path);
            ListentoAudio.clip = OpenWavParser.ByteArrayToAudioClip(wavFile);
            ListentoAudio.Play();
            Text.text = "playing over";
        }
        else
        {
            Debug.Log("File not found");
            Debug.Log(path);
            Text.text = "File not found";
        }


        //  StartCoroutine(AudioPLaying());
    }
    // Called in separate thread. Must not contain unity object invokation/creation
    void LoadClip()
    {
        var path = model.itemToPlay.path;

        if (File.Exists(path))
        {
            byte[] data = File.ReadAllBytes(path);

            if (model.audioModel != null)
            {
                model.audioModel.data = null;
            }

            model.audioModel = Util.isMP3(path) ? NAudioConverter.FromMp3DataModel(ref data) : OpenWavParser.ByteArrayToAudioClipModel(data);
        }
        else
        {
            throw new UnityException("File not exists: " + path);
        }
        clipLoadInProgress = false;
    }
 public void SaveClip()
 {
     byte[] wavFile = OpenWavParser.AudioClipToByteArray(source.clip);
     File.WriteAllBytes(Application.persistentDataPath + "/MyFile.wav", wavFile);
 }