---
# System prepended metadata

title: 語音辨識修正 (GoogleSpeechRecognizer.cs)

---

# 語音辨識修正 (GoogleSpeechRecognizer.cs)

## 老樣子，又是路徑問題
在 

```csharp=107
            string credentialsPath = Path.Combine(Application.streamingAssetsPath, CredentialFileName); // 這是原本的 GCP 憑證位置
```

添加

```csharp=109
#if UNITY_ANDROID
            // 因為 Android 不能直接讀 StreamingAssets，所以我們要搬它
            var unityWebRequest = UnityEngine.Networking.UnityWebRequest.Get(credentialsPath);
            unityWebRequest.SendWebRequest();
            while (!unityWebRequest.isDone) { }            
            credentialsPath = Path.Combine(Application.persistentDataPath, CredentialFileName); // 常識改變活動紀錄
            File.WriteAllText(credentialsPath, unityWebRequest.downloadHandler.text);
#endif
```

## 辨識時間太長它會罷工
雖然正確的解法是有需要辨識的時候再開它，
但我們的超爛解法是不定時去開關它就好了

```cs=146
            StartCoroutine(PeriodlyRestart());
        }

        /// <summary>
        /// BADBADBADBAD
        /// </summary>
        IEnumerator PeriodlyRestart()
        {
            while (true)
            {
                yield return new WaitForSeconds(30f);
                print("[StreamingRecognizer] Restarting");
                Restart();
            }
        }
```