Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class VoiceFileAdjuster : MonoBehaviour {
  6. AudioClip clip;
  7. string voiceFilePath;
  8. public MinMaxSlider minMaxSlider;
  9.  
  10. void Start() {
  11. //string path = "c:\\kc\\recTest_"+i+".wav";
  12. //voiceFilePath = "\\" + LoaderScript.SP.instructorXMLPath.Replace (".xml", ".wav");//something happen maybe
  13. StartCoroutine(GetAudioClipFromFile());
  14. //test if createOffsetClip is working
  15. // clip = createOffsetAudioClip (clip, 5.8f); //offset by 6 seconds
  16. string[] parts = voiceFilePath.Split('\\');
  17. clip.name = parts[parts.Length - 1];
  18.  
  19. }
  20. IEnumerator GetAudioClipFromFile()
  21. {
  22. voiceFilePath = Application.dataPath + @"/../KinectCoachAlbum/" + voiceFilePath;//FullPathOfWavFiles
  23. WWW www = new WWW("file://" + voiceFilePath);
  24. yield return new WaitForEndOfFrame();
  25.  
  26. clip = www.GetAudioClip();
  27. Debug.Log(clip.length);
  28. Debug.Log(clip.samples);
  29. }
  30.  
  31. public void createOffsetAudioClip()
  32. {
  33. //create audio clip that skip offset period.
  34. float lengthL = clip.length; //in seconds
  35. float samplesL = clip.samples;
  36.  
  37. float offset = ( (float)minMaxSlider.minFrameValue/(float)minMaxSlider.getTotalFrame()) * samplesL;
  38. if (offset > 0.0f) {
  39. float[] smpl = new float[((int)(samplesL - offset))];
  40. AudioClip newAudioClip = AudioClip.Create ("cutclip", (int)(samplesL - offset),
  41. clip.channels, clip.frequency, false);
  42. clip.GetData(smpl, (int)(offset)); //Pull the data from the clip with an offset of seconds. We devide by the time per second to actually offset by a perfect 20 seconds instead of something shorter or longer.
  43. newAudioClip.SetData (smpl, 0); //We pulled the data from the original with an offset of 20 seconds, now we apply it to the new with no offset, making this audio clip 20 seconds ahead of the original.
  44. Debug.Log(voiceFilePath);
  45. SavWav.Save (voiceFilePath, newAudioClip);
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement