code works in editor but not in android

Hello

I’ve got my editor build set for android, and the following code:

speechText = GameObject.Find ("SpeechLabel").GetComponent<UILabel> ();
		GetComponent<AudioSource>().clip = Microphone.Start (null,false,5,8000);
		yield return new WaitForSeconds(5);
		Microphone.End(null);
		GetComponent<AudioSource>().Play(); //hear whatw e got
		float[] clipData = new float[GetComponent<AudioSource>().clip.samples *             GetComponent<AudioSource>().clip.channels];
		GetComponent<AudioSource>().clip.GetData(clipData,0);
		WaveGen.WaveFormatChunk format = new      WaveGen().MakeFormat(GetComponent<AudioSource>().clip);
		string filename = Application.persistentDataPath + "/" + "recordedSpeech.wav";
		FileStream stream = File.OpenWrite(filename);
		new WaveGen().Write (clipData,format,stream);
		stream.Close();
		SpeechResponse response = requestFactory.SpeechToText (filename);
		string transcribedText = response.Recognition.NBest[0].ResultText;
		speechText.text = transcribedText;

When i’m debugging the code on android it seems to stop on these lines :

                    SpeechResponse response = requestFactory.SpeechToText (filename);
    		string transcribedText = response.Recognition.NBest[0].ResultText;

I get these errors on iOS…

creating a file in local path
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65)
 
Check response from API
(Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 65)
 
TlsException: The authentication or decryption has failed.
  at Mono.Math.BigInteger+Kernel.Multiply (System.UInt32[] x, UInt32 xOffset, UInt32 xLen, System.UInt32[] y, UInt32 yOffset, UInt32 yLen, System.UInt32[] d, UInt32 dOffset) [0x00000] in <filename unknown>:0
  at Mono.Security.Protocol.Tls.RecordProtocol.ProcessAlert (AlertLevel alertLevel, AlertDescription alertDesc) [0x00000] in <filename unknown>:0
  at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
  at System.IO.Stream.BeginRead (System.Byte[] buffer, Int32 offset, Int32 count, System.AsyncCallback callback, System.Object state) [0x00000] in <filename unknown>:0
  at Mono.Security.Protocol.Tls.RecordProtocol.BeginReceiveRecord (System.IO.Stream record, System.AsyncCallback callback, System.Object state) [0x00000] in <filename unknown>:0
  at Mono.Security.Protocol.Tls.SslStreamBase.InternalReadCallback (IAsyncResult result) [0x00000] in <filename unknown>:0
  at System.Net.Sockets.Socket+SocketAsyncResult.Complete () [0x00000] in <filename unknown>:0
Rethrow as WebException: Error getting response stream (ReadDone1): ReceiveFailure
  at System.Net.Configuration.BypassElementCollection.set_Item (Int32 index, System.Net.Configuration.BypassElement value) [0x00000] in <filename unknown>:0
  at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
  at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
  at ATT_MSSDK.RequestFactory.Send (HTTPMethods method, System.String relativeUri, System.Collections.Specialized.NameValueCollection headers, System.Byte[] bodyBytes, System.String contentType, System.String accept, Boolean returnWebResponse) [0x00000] in <filename unknown>:0
  at ATT_MSSDK.RequestFactory.Send (HTTPMethods method, System.String relativeUri, System.Collections.Specialized.NameValueCollection headers, System.String body, System.String contentType, System.String accept) [0x00000] in <filename unknown>:0
  at ATT_MSSDK.RequestFactory.GetNewClientCredential () [0x00000] in <filename unknown>:0
  at ATT_MSSDK.RequestFactory.GetClientCredentials () [0x00000] in <filename unknown>:0
  at ATT_MSSDK.RequestFactory.ConvertToText (System.String audioFilePath, System.String speechContext, Nullable`1 xSpeechContext, System.String xArgsParameter, System.Collections.Specialized.NameValueCollection xArgsCollection, ATT_MSSDK.Speechv3.XArgs xArgs) [0x00000] in <filename unknown>:0
  at ATT_MSSDK.RequestFactory.SpeechToText (System.String audioFilePath) [0x00000] in <filename unknown>:0
  at VoiceRec+<DoRecognize>c__Iterator17.MoveNext () [0x00000] in <filename unknown>:0
Rethrow as InvalidResponseException: Failed: Unable to get response
  at ATT_MSSDK.RequestFactory..ctor (System.String endPoint, System.String clientId, System.String clientSecret, System.Collections.Generic.List`1 scopes, System.String redirectUri, System.String proxyAddress) [0x00000] in <filename unknown>:0
  at ATT_MSSDK.RequestFactory.Send (HTTPMethods method, System.String relativeUri, System.Collections.Specialized.NameValueCollection headers, System.Byte[] bodyBytes, System.String contentType, System.String accept, Boolean returnWebResponse) [0x00000] in <filename unknown>:0
  at ATT_MSSDK.RequestFactory.Send (HTTPMethods method, System.String relativeUri, System.Collections.Specialized.NameValueCollection headers, System.String body, System.String contentType, System.String accept) [0x00000] in <filename unknown>:0
  at ATT_MSSDK.RequestFactory.GetNewClientCredential () [0x00000] in <filename unknown>:0
  at ATT_MSSDK.RequestFactory.GetClientCredentials () [0x00000] in <filename unknown>:0
  at ATT_MSSDK.RequestFactory.ConvertToText (System.String audioFilePath, System.String speechContext, Nullable`1 xSpeechContext, System.String xArgsParameter, System.Collections.Specialized.NameValueCollection xArgsCollection, ATT_MSSDK.Speechv3.XArgs xArgs) [0x00000] in <filename unknown>:0
  at ATT_MSSDK.RequestFactory.SpeechToText (System.String audioFilePath) [0x00000] in <filename unknown>:0
  at VoiceRec+<DoRecognize>c__Iterator17.MoveNext () [0x00000] in <filename unknown>:0
(Filename: currently not available on il2cpp Line: -1)

I think this has something to do with how you read and write files on android versus doing it in the editor. I ended up using the resources folder - something sort of like this (this is raw straight from one of my projects, so you’ll need to adapt it to your needs):

	void LoadSomething() // loads a text asset (in my case a binary file)
	{
		string resourcePath = pD.MapName + "_AlphaPixels"; // a string that only contains the name of the file (its in resources folder)
		TextAsset asset = (TextAsset)Resources.Load(resourcePath, typeof(TextAsset));
		Stream binaryStream;
		
		if(asset == null)
			Debug.LogError("ERROR: binaryStream null!");
		
		binaryStream = new MemoryStream(asset.bytes);
		
		yield return new WaitForEndOfFrame();

		// in my project I have to take binary data out of the file this way - you would handle your data differently most likely
		using(BinaryReader reader = new BinaryReader(binaryStream))
		{
			int toLoad;
			
			for(int i = 0; i < worldAlphaPixels.Length; )
			{
				toLoad = reader.ReadInt32();
				
				for(int x = 0; x < 32 && i < worldAlphaPixels.Length; )
				{
					worldAlphaPixels *= ((toLoad >> x) & 1) == 1; // here I am actually assigning values based on the binary file*
  •  			x++;*
    
  •  			i++;*
    
  •  		}*
    
  •  	}*
    
  •  	reader.Close();*
    
  •  }*
    
  • }*
    Hope that helps!

Judging by this error:

System.Net.Sockets.Socket+SocketAsyncResult.Complete () [0x00000] in <filename unknown>:0
 Rethrow as WebException: Error getting response stream

You have something wrong in your POST request. Try checking to make sure your http request is formatted correctly.