Пример #1
1
        public IEnumerator AddWavFIle(string path, string fileName, string strNum)
        {
            var type = AudioType.OGGVORBIS;

            if (File.Exists(path + fileName + ".wav"))
            {
                fileName += ".wav";
                type      = AudioType.WAV;
            }
            else if (File.Exists(path + fileName + ".ogg"))
            {
                fileName += ".ogg";
                type      = AudioType.OGGVORBIS;
            }
            else if (File.Exists(path + fileName + ".mp3"))
            {
                fileName += ".mp3";
                type      = AudioType.OGGVORBIS;
            }

            using (var www = UnityWebRequestMultimedia.GetAudioClip("file:///" + path + UnityWebRequest.EscapeURL(fileName), type))
            {
                yield return(www.SendWebRequest());

                if (www.downloadHandler.data.Length == 0)
                {
//                    Debug.Log(www.downloadHandler.data);
                    Debug.Log($"{path}{UnityWebRequest.EscapeURL(fileName)}, {strNum} {type.ToString()} doesnt find in files");
                    Debug.Log($"{www.error}");
                    Head.WavFiles.Add(strNum, null);
                }
                else
                {
                    var audio = DownloadHandlerAudioClip.GetContent(www);
                    audio.LoadAudioData();
                    Head.WavFiles.Add(strNum, audio);
                }
            }
        }
Пример #2
0
    IEnumerator Speaking()
    {
        string word = null;

        for (int i = 0; i < slots.Count; i++)
        {
            if (!slots[i].GetComponentInChildren <PhoneticManager>())
            {
                word += " ";
                //yield return new WaitForSeconds(.25f);
            }
            else
            {
                //For Google Translator

                word += slots[i].GetComponentInChildren <PhoneticManager>().phoneme;

                //speech.Speak(slots[i].GetComponentInChildren<PhoneticManager>().audioClip);
                //yield return new WaitForSeconds(slots[i].GetComponentInChildren<PhoneticManager>().audioClip.length/1.5f);
            }
        }

        string url = "https://translate.google.com/translate_tts?ie=UTF-8&total=1&idx=0&textlen=32&client=tw-ob&q=" +
                     word + "&tl=En-gb";
        UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, AudioType.MPEG);

        yield return(www.Send());

        result.text = word;

        if (!www.isNetworkError)
        {
            audioClip = DownloadHandlerAudioClip.GetContent(www);
        }
        speech.Speak(audioClip);
        yield return(new WaitForSeconds(audioClip.length));

        result.text = "";
    }
Пример #3
0
    IEnumerator GetAudioClip()
    {
        using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("http://wiggly.laar.world/vln5.wav", AudioType.WAV))
        {
            yield return(www.SendWebRequest());


            if (www.isNetworkError)
            {
                Debug.Log(www.error);
            }
            else
            {
                myClip           = DownloadHandlerAudioClip.GetContent(www);
                audioSource.clip = myClip;
                //audioSource.Play();
                Debug.Log("Audio has downloaded.");
                Playtext.GetComponent <Text>().enabled    = true;
                Playbutton.GetComponent <Image>().enabled = true;
            }
        }
    }
Пример #4
0
    /// <summary>
    /// 取得音频
    /// </summary>
    /// <param name="path"></param>
    /// <param name="ac"></param>
    /// <returns></returns>
    public static IEnumerator GetAudio(string path, string aname, System.Action <string, AudioClip> ac)
    {
        yield return(new WaitForSeconds(0.1f));

#if UNITY_STANDALONE_WIN
        NAudioTools.LAudioConver conver = null;
        try
        {
            conver = new NAudioTools.LAudioConver(path);
            path   = conver.GetWavAudioPath;
        }
        catch
        {
            GlobalUIManager.guim.CreateNewDialogTie("转码出现异常!");
        }


        UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.UNKNOWN);
#endif

#if UNITY_ANDROID
        UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip("file://" + path, AudioType.UNKNOWN);
#endif
        yield return(uwr.SendWebRequest());

        //  Debug.Log(path);

        if (uwr.error == "" || uwr.error == null)
        {
            ac?.Invoke(aname, DownloadHandlerAudioClip.GetContent(uwr));
        }
        else
        {
            ac?.Invoke(aname, null);
        }
#if UNITY_STANDALONE_WIN
        conver.DestoryThis();
#endif
    }
Пример #5
0
    //load the audio using unitywebrequest to stream the audio file
    IEnumerator LoadAudio(string songlocation, AudioSource audiosource)
    {
        if (File.Exists(songlocation))
        {
            using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("file:///" + songlocation, AudioType.WAV))
            {
                //wait for the audio file to be ready
                yield return(www.SendWebRequest());

                //check if an error has occurred
                if (www.isNetworkError)
                {
                    Debug.Log(www.error);
                }
                else
                {
                    audiosource.clip = DownloadHandlerAudioClip.GetContent(www);
                }
            }
            audiosource.Play();
        }
    }
Пример #6
0
        IEnumerator GetAudioClip(string uri)
        {
            using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(uri, AudioType.OGGVORBIS)) {
                yield return(www.SendWebRequest());

                if (www.isNetworkError)
                {
                    UnityEngine.Debug.Log(www.error);
                }
                else
                {
                    audioFile = DownloadHandlerAudioClip.GetContent(www);

                    Double.TryParse(bpmInput.text, out bpm);

                    timeline.LoadTimingMode(audioFile);


                    yield break;
                }
            }
        }
Пример #7
0
    IEnumerator LoadSong(string p)
    {
        // gets info from the file path of the song
        string[] splitPath = p.Split('/');
        string   temp      = splitPath[splitPath.Length - 1];

        string[] temp2 = temp.Split('.');
        songName           = temp2[0];
        songNameInput.text = songName;
        songURL            = string.Format("file://{0}", p);
        //gets the song
        UnityWebRequest songRequest = UnityWebRequestMultimedia.GetAudioClip(songURL, AudioType.WAV);

        yield return(songRequest.SendWebRequest());

        DownloadHandlerAudioClip handler = (DownloadHandlerAudioClip)songRequest.downloadHandler;

        // once its gotten it sets the song clip.
        songClip   = handler.audioClip;
        song.clip  = songClip;
        songLength = songClip.length;
    }
Пример #8
0
        private void SynthesisInEditor(string text, string savePath, SynthesisType audioType = SynthesisType.MP3, int timeout = 60000, Speaker speaker = Speaker.DuYaYa, int volume = 15, int speed = 5, int pitch = 5)
        {
            if (string.IsNullOrEmpty(text) || text == "" || Encoding.Default.GetByteCount(text) >= 1024)
            {
                Log.Error("合成语音失败:文本为空或长度超出了1024字节的限制!");
                return;
            }
            if (File.Exists(savePath))
            {
                Log.Error("合成语音失败:已存在音频文件 " + savePath);
                return;
            }

            string url = string.Format("{0}?tex='{1}'&tok={2}&cuid={3}&ctp={4}&lan={5}&spd={6}&pit={7}&vol={8}&per={9}&aue={10}",
                                       SynthesisAPI, text, TOKEN, SystemInfo.deviceUniqueIdentifier, 1, "zh", speed, pitch, volume, (int)speaker, (int)audioType);

            UnityWebRequest request             = UnityWebRequestMultimedia.GetAudioClip(url, audioType == SynthesisType.MP3 ? AudioType.MPEG : AudioType.WAV);
            UnityWebRequestAsyncOperation async = request.SendWebRequest();

            async.completed += SynthesisDone;
            _isSynthesis     = true;
        }
Пример #9
0
        /// <summary>
        /// Load the audio from path/url in runtime.
        /// </summary>
        /// <param name="url"> Url to the target audio file. </param>
        /// <param name="type"> Type of the audio clip. </param>
        /// <param name="callback"> Callback after the audio is loaded. </param>
        /// <returns> Coroutine status. </returns>
        public static IEnumerator LoadAudio(
            string url,
            AudioType type       = AudioType.OGGVORBIS,
            AudioLoaded callback = null)
        {
#if UNITY_2018_1_OR_NEWER
            UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(url, type);
            yield return(request.SendWebRequest());

            AudioClip ac = DownloadHandlerAudioClip.GetContent(request);
#else
            WWW request = new WWW(url);
            yield return(request);

            AudioClip ac = request.GetAudioClip(false, false);
#endif

            if (callback != null)
            {
                callback.Invoke(ac);
            }
        }
Пример #10
0
    private static AudioClip LoadAudio(string path, bool streamAudio)
    {
        using (UnityWebRequest webRequest = UnityWebRequestMultimedia.GetAudioClip("file://" + path, AudioType.UNKNOWN))
        {
            DownloadHandlerAudioClip downloadHandler = webRequest.downloadHandler as DownloadHandlerAudioClip;
            downloadHandler.streamAudio = streamAudio;

            webRequest.SendWebRequest();
            if (webRequest.isNetworkError || webRequest.isHttpError)
            {
                Debug.LogError("Error Loading Audio: " + path);
                Debug.LogError(webRequest.error);
                return(null);
            }

            while (!webRequest.isDone)
            {
                Task.Delay(30);
            }
            return(downloadHandler.audioClip);
        }
    }
Пример #11
0
    IEnumerator DownloadAudioFromServer()
    {
        //www = UnityWebRequest.Get("https://echoes.etc.cmu.edu/api/viewer/events/" + eventId + "/sound");
        //yield return www.SendWebRequest();


        www = UnityWebRequestMultimedia.GetAudioClip("https://file-examples.com/wp-content/uploads/2017/11/file_example_WAV_1MG.wav", AudioType.WAV);
        yield return(www.SendWebRequest());



        if (www.isNetworkError || www.isHttpError)
        {
            Debug.Log(www.error + " : " + www.downloadHandler.text);
        }
        else
        {
            Debug.Log("Download complete!");
            download_audioClip = DownloadHandlerAudioClip.GetContent(www);
            //PlayAudio();
        }
    }
Пример #12
0
 public void Download()
 {
     if (mLoadState == AssetLoadState.Done)
     {
         if (Error)
         {
             OnFail2Load();
         }
         else
         {
             OnSuccess2Load();
         }
         return;
     }
     if (mLoadState != AssetLoadState.None)
     {
         return;
     }
     if (mAssetType == typeof(AssetBundle))
     {
         mWBER = UnityWebRequestAssetBundle.GetAssetBundle(AssetPath);
     }
     else if (mAssetType == typeof(AudioClip))
     {
         mWBER = UnityWebRequestMultimedia.GetAudioClip(AssetPath, AudioType.WAV);
     }
     else if (mAssetType == typeof(Texture2D))
     {
         mWBER = UnityWebRequestTexture.GetTexture(AssetPath);
     }
     else
     {
         mWBER = new UnityWebRequest(AssetPath);
         mWBER.downloadHandler = new DownloadHandlerBuffer();
     }
     mWBER.SendWebRequest();
     mLoadState = AssetLoadState.Loading;
     NetAssetManager.Instance.PushInAsyncList(this);
 }
Пример #13
0
    IEnumerator GetAudioClip(string path, string name, int replaceIndex)
    {
        AudioType t = GetTypeFromFile(name);

        if (t != AudioType.MPEG)
        {
            using (UnityWebRequest r = UnityWebRequestMultimedia.GetAudioClip(path, t))
            {
                yield return(r.SendWebRequest());

                if (r.isNetworkError || r.isHttpError)
                {
                    Debug.Log(r.error);
                }
                else
                {
                    selectedClip = DownloadHandlerAudioClip.GetContent(r);
                    if (selectedClip)
                    {
                        previewSource.clip = selectedClip;
                    }
                }
            }

            if (selectedClip)
            {
                previewSource.clip = selectedClip;
            }
        }
        else
        {
            string p = ConvertMPEG(path, replaceIndex);
            if (replaceIndex < _audioClips.Count)
            {
                _audioClips[replaceIndex] = p;
                RefreshFiles();
            }
        }
    }
Пример #14
0
    IEnumerator GetAudioClips(FileObj fileObj)
    {
        string basePath = fileObj.directory.FullName;

        Debug.Log(basePath);

        for (int i = 0; i < fileObj.info.audios.Count; i++)
        {
            string fileName = fileObj.info.audios[i];
            string path     = Path.Combine(basePath, fileName);
            Debug.Log(path);
            audios.Add(null);
            if (File.Exists(path))
            {
                Debug.Log($"{i}: {path}");
            }
            else
            {
                Debug.Log($"{i}: audio file {path} not exists.");
                continue;
            }


            using (UnityWebRequest www =
                       UnityWebRequestMultimedia.GetAudioClip(path, AudioType.WAV))
            {
                yield return(www.SendWebRequest());

                if (www.isNetworkError)
                {
                    Debug.Log(path + " : ERROR");
                    break;
                }

                audios[audios.Count - 1] = DownloadHandlerAudioClip.GetContent(www);
            }
        }
    }
Пример #15
0
        IEnumerator GenerateAudioClip(AudioSource audioSource, string filenameWithExtension, bool play = false)
        {
            if (memorizedClips.ContainsKey(filenameWithExtension))
            {
                audioSource.clip = memorizedClips[filenameWithExtension];
            }
            else
            {
                string filePath = Environment.CurrentDirectory.Replace('\\', '/') + "/UserData/Chroma/Audio/" + filenameWithExtension;
                ChromaLogger.Log("Searching for audio file " + filePath, ChromaLogger.Level.DEBUG, false);
                using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(filePath, AudioType.WAV)) {
                    yield return(www.SendWebRequest());

                    if (www.isHttpError || www.isNetworkError)
                    {
                        ChromaLogger.Log(www.error, ChromaLogger.Level.ERROR, false);
                        yield break;
                    }
                    else
                    {
                        ChromaLogger.Log("Found sound " + filenameWithExtension, ChromaLogger.Level.ERROR, false);
                        AudioClip downloadedClip = DownloadHandlerAudioClip.GetContent(www);
                        if (downloadedClip == null)
                        {
                            ChromaLogger.Log("Failed to find sound " + filePath, ChromaLogger.Level.WARNING, false);
                            yield break;
                        }
                        audioSource.clip = downloadedClip;
                        memorizedClips[filenameWithExtension] = downloadedClip;
                    }
                }
            }
            if (play)
            {
                audioSource.Play();
            }
            yield break;
        }
Пример #16
0
    IEnumerator GetAudioClip(string path, int time = 0)
    {
        // using (var uwr = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.MPEG))
        // {
        //     yield return uwr.SendWebRequest();
        //     if (uwr.isNetworkError)
        //     {
        //         Log.E(uwr.error);
        //         yield break;
        //     }
        //
        //     AudioClip clip = DownloadHandlerAudioClip.GetContent(uwr);
        //     mAudioSource.clip = clip;
        //     mAudioSource.time = time;
        //     mAudioSource.Play();
        //     mPlayStatus.Value = PlayStatus.Playing;
        // }
        using (var uwr = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.UNKNOWN))
        {
            //不卡顿的2行代码
            ((DownloadHandlerAudioClip)uwr.downloadHandler).compressed  = false;
            ((DownloadHandlerAudioClip)uwr.downloadHandler).streamAudio = true;
            yield return(uwr.SendWebRequest());

            if (uwr.isNetworkError)
            {
                Log.E(uwr.error);
            }
            else
            {
                AudioClip clip = DownloadHandlerAudioClip.GetContent(uwr);
                mAudioSource.clip = clip;
                mAudioSource.time = time;
                mAudioSource.Play();//播放
                mPlayStatus.Value = PlayStatus.Playing;
            }
        }
    }
Пример #17
0
    public async UniTask Load()
    {
        if (loaded)
        {
            Unload();
        }
        
        var type = AudioTypeExtensions.Detect(Path);
        
        // TODO: Load remote mp3 with non-mobile platform (Download with UnityWebRequest first?)
        // Load .mp3 with NLayer on non-mobile platforms
        if (
            Path.StartsWith("file://")
            && type == AudioType.MPEG
            && Application.platform != RuntimePlatform.Android 
            && Application.platform != RuntimePlatform.IPhonePlayer
        )
        {
            nLayerLoader = new NLayerLoader(Path);
            AudioClip = nLayerLoader.LoadAudioClip();
        }
        else
        {
            using (var request = UnityWebRequestMultimedia.GetAudioClip(Path, type))
            {
                await request.SendWebRequest();
                if (request.isNetworkError || request.isHttpError)
                {
                    Error = request.error;
                    return;
                }

                AudioClip = DownloadHandlerAudioClip.GetContent(request);
            }
        }

        loaded = true;
    }
Пример #18
0
        public static IEnumerator FetchAudioClip(string url, AudioType audioType, Action <AudioClip> OnSuccess,
                                                 Action <string> OnFail)
        {
            //NOTE(Brian): This closure is called when the download is a success.
            Action <UnityWebRequest> OnSuccessInternal =
                (request) =>
            {
                if (OnSuccess != null)
                {
                    bool supported = true;
#if UNITY_EDITOR
                    supported = audioType != AudioType.MPEG;
#endif
                    AudioClip ac = null;

                    if (supported)
                    {
                        ac = DownloadHandlerAudioClip.GetContent(request);
                    }

                    OnSuccess.Invoke(ac);
                }
            };

            Action <string> OnFailInternal =
                (error) =>
            {
                if (OnFail != null)
                {
                    OnFail.Invoke(error);
                }
            };

            var req = UnityWebRequestMultimedia.GetAudioClip(url, audioType);

            yield return(FetchAsset(url, req, OnSuccessInternal,
                                    OnFailInternal));
        }
Пример #19
0
    IEnumerator GetSongFromDifficultyData(BeatSaberMap map)
    {
        BeatSaberSong.DifficultyBeatmap data = songDifficultyData[selectedDifficultyIndex];
        string directory = Song.directory;

        if (File.Exists(directory + "/" + Song.songFilename))
        {
            if (Song.songFilename.ToLower().EndsWith("ogg") || Song.songFilename.ToLower().EndsWith("egg"))
            {
                UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip($"file:///{Uri.EscapeDataString($"{directory}/{Song.songFilename}")}", AudioType.OGGVORBIS);
                //Escaping should fix the issue where half the people can't open ChroMapper's editor (I believe this is caused by spaces in the directory, hence escaping)
                yield return(www.SendWebRequest());

                Debug.Log("Song loaded!");
                AudioClip clip = DownloadHandlerAudioClip.GetContent(www);
                if (clip == null)
                {
                    Debug.Log("Error getting Audio data!");
                    SceneTransitionManager.Instance.CancelLoading("Error getting Audio data!");
                }
                clip.name = "Song";
                BeatSaberSongContainer.Instance.loadedSong     = clip;
                BeatSaberSongContainer.Instance.difficultyData = data;
                //TransitionToEditor(map, clip, data);
            }
            else
            {
                Debug.Log("Incompatible file type! WTF!?");
                SceneTransitionManager.Instance.CancelLoading("Incompatible audio type!");
            }
        }
        else
        {
            SceneTransitionManager.Instance.CancelLoading("Audio file does not exist!");
            Debug.Log("Song does not exist! WTF!?");
            Debug.Log(directory + "/" + Song.songFilename);
        }
    }
Пример #20
0
        private static AudioClip LoadUnityAudioClip(string ftype, string filePath)
        {
            try
            {
                Utils.Log("Loading Unity clip: " + filePath);
                // Load the audio clip into memory.


#if false
#if false
                filePath = filePath.Replace(@"\", "/");
                filePath = Path.GetFileName(filePath);
                Debug.Log("filepath.Replace:" + filePath);
                AudioClip clip = Resources.Load(Path.GetFileNameWithoutExtension(filePath)) as AudioClip;
                if (clip == null)
                {
                    Debug.Log("LoadUnityAudioclip  loading clip failed");
                }
#else
                UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip(filePath,
                                                                             ftype == ".WAV" ? AudioType.WAV : AudioType.OGGVORBIS);
                AudioClip clip = DownloadHandlerAudioClip.GetContent(uwr);
#endif
#else
                WWW       www  = new WWW("file://" + filePath);
                AudioClip clip = www.GetAudioClip();
#endif

                clip.name = Path.GetFileNameWithoutExtension(filePath);
                Utils.Log("Clip name: " + clip.name + ", load state: " + clip.loadState);
                return(clip);
            }
            catch (Exception ex)
            {
                Debug.LogError("[STED] Error loading audio file " + filePath + ": " + ex.Message + "\r\n" + ex.StackTrace);
                return(null);
            }
        }
Пример #21
0
        private static IEnumerator SynthesisCoroutine(string text, HTFAction <AudioClip> handler, HTFAction failHandler, int timeout, Speaker speaker, int volume, int speed, int pitch)
        {
            string url = string.Format("{0}?tex='{1}'&tok={2}&cuid={3}&ctp={4}&lan={5}&spd={6}&pit={7}&vol={8}&per={9}&aue={10}",
                                       SynthesisAPI, text, TOKEN, SystemInfo.deviceUniqueIdentifier, 1, "zh", speed, pitch, volume, (int)speaker, 6);

            using (UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(url, AudioType.WAV))
            {
                yield return(request.SendWebRequest());

                if (!request.isNetworkError && !request.isHttpError)
                {
                    AudioClip audioClip = DownloadHandlerAudioClip.GetContent(request);

                    handler?.Invoke(audioClip);
                }
                else
                {
                    Log.Error("合成语音失败:" + request.responseCode + " " + request.error);

                    failHandler?.Invoke();
                }
            }
        }
Пример #22
0
    IEnumerator GetAudioClip(string url)
    {
        using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, AudioType.WAV))
        {
            yield return(www.SendWebRequest());

            if (www.isNetworkError)
            {
                Debug.Log(www.error);
            }
            else
            {
                AudioClip clip = DownloadHandlerAudioClip.GetContent(www);

                Debug.Log(clip + " length: " + clip.length);
                if (clip)
                {
                    GetComponent <AudioSource>().clip = clip;
                    GetComponent <AudioSource>().Play();
                }
            }
        }
    }
Пример #23
0
 public void Play()
 {
     // Load the sheet data
     try {
         Sheet sheet = FileSystem.Load_MusicSheet(path.sheetpath);
         wrapper.data = sheet;
         if (sheet != null)
         {
             // Load music using web request
             string uri = "file:///" + path.musicpath;
             Debug.Log(uri);
             UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip(uri, G.CRAFT.mtype[path.musictype]);
             StartCoroutine(getaudioclip(req));
         }
         else
         {
             msgbox.Show(G.lang.message_load_musicdata_failure[G.setting.language]);
         }
     } catch (Exception e) {
         msgbox.Show(G.lang.message_onload_musicdata_error[G.setting.language]);
         Debug.Log(e.Message);
     }
 }
Пример #24
0
    /// <summary>
    /// Coroutine which loads a audio clip from an external file and plays it with given audio source.
    /// </summary>
    /// <param name="audioSource">Audio source to play the external audio with.</param>
    /// <param name="filePath">Audio file path.</param>
    /// <returns></returns>
    public static IEnumerator PlayExternalAudioClip(AudioSource audioSource, string filePath)
    {
        if (File.Exists(filePath))
        {
            //Change the audio type if you want to load anything else except .ogg
            //TODO: Check for possible file endings.
            UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(filePath, AudioType.OGGVORBIS);
            yield return(request.SendWebRequest());

            AudioClip audioClip = DownloadHandlerAudioClip.GetContent(request);

            if (audioClip != null)
            {
                audioSource.clip = audioClip;
                audioSource.Play();
                audioSource.loop = false;
            }
        }
        else
        {
            Debug.LogError("Audio File does not exist.");
        }
    }
Пример #25
0
    IEnumerator OpenMusic()
    {
        var sfd = new SelectFileDialog()
                  .SetFilter("Music file\0*.ogg\0")
                  .SetTitle("Select music")
                  .SetDefaultExt("ogg")
                  .Show();

        if (sfd.IsSucessful)
        {
            var type = AudioType.OGGVORBIS;

            using (var uwrm = UnityWebRequestMultimedia.GetAudioClip("file:///" + sfd.File.Replace('\\', '/'), type))
            {
                yield return(uwrm.SendWebRequest());

                if (!uwrm.isNetworkError)
                {
                    ass.clip = DownloadHandlerAudioClip.GetContent(uwrm);
                }
            }
        }
    }
    IEnumerator LoadAudioFile(string path, Action <AudioClip> action)
    {
        UnityWebRequest AudioFiles = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.UNKNOWN);

        yield return(AudioFiles.SendWebRequest());

        if (AudioFiles.isNetworkError)
        {
            Debug.Log(AudioFiles.error);
        }
        else
        {
            try
            {
                AudioClip clip = DownloadHandlerAudioClip.GetContent(AudioFiles);
                action.Invoke(clip);
            }
            catch
            {
                action.Invoke(null);
            }
        }
    }
Пример #27
0
    IEnumerator GetPercAudio7()
    {
        using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url7, AudioType.WAV))
        {
            yield return(www.SendWebRequest());


            if (www.isNetworkError)
            {
                Debug.Log(www.error);
            }
            else
            {
                myClip7           = DownloadHandlerAudioClip.GetContent(www);
                audioSource7.clip = myClip7;

                isThisDownloading.itemsDownloaded++;
                isThisDownloading.ChangeText();

                audioSource7.enabled = true;
            }
        }
    }
Пример #28
0
    IEnumerator GetAudioClip(string path)
    {
        print("Loading... " + path);

        AudioClip audioClip = null;

        using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.WAV))
        {
            yield return(www.SendWebRequest());

            if (www.isHttpError || www.isNetworkError)
            {
                Debug.Log(www.error);
            }
            else
            {
                audioClip = DownloadHandlerAudioClip.GetContent(www);
                _Clips.Add(audioClip);

                print("Loading complete: " + path);
            }
        }
    }
Пример #29
0
    IEnumerator DownloadTheAudio()
    {
        string url = "https://translate.google.com/translate_tts?ie=UTF-8&total=1&idx=0&textlen=32&client=tw-ob&q=" + guide.text + "&tl=ko-kr";

        //+ "도움이 필요하신 고객님께는 주문하신 음식을 자리로 가져다 드리고 있습니다."
        //+ "해당 서비스가 필요하시면 파란색 네모 안을, 필요하지 않으시면 빨간색 네모 안을 눌러주세요."
        //+ "&tl=ko-kr";
        //string url = "https://google-translate-proxy.herokuapp.com/api/tts?query=" + guide.text + "&language=ko&speed=0.38";

        //WWW www = new WWW(url);
        //yield return www;

        using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, AudioType.MPEG))
        {
            www.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");
            yield return(www.SendWebRequest());

            _audio.clip = DownloadHandlerAudioClip.GetContent(www);
        }

        //_audio.clip = www.GetAudioClip(true, false, AudioType.MPEG);
        _audio.Play();
    }
Пример #30
0
    IEnumerator StreamAudioV3()
    {
        UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, AudioType.WAV);

        yield return(www.SendWebRequest());

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.Log(www.error);
        }
        else
        {
            clip = DownloadHandlerAudioClip.GetContent(www);

            Debug.LogFormat("Waiting for AudioClip: bytes={0}", www.downloadedBytes);

            if (clip != null)
            {
                source.clip = clip;
                source.Play();
            }
        }
    }