1

Context

I have to implement a Speech to Text feature in a Xamarin.iOS app using Google Cloud Speech api.

The audio needs to be streamed as the user speaks, so that we can show what the user says as soon as we can.

Firstly I tried to use the Google.Cloud.Speech.V1 Nuget package but the gRPC library seems to not working with Xamarin (https://github.com/grpc/grpc/issues/1620, https://forums.xamarin.com/discussion/94534/how-to-use-google-cloud-speech-api-within-xamarin-forms, Xamarin, Grpc, Could not resolve type with token 0100002b).

So I tried to create a binding over this sample: https://github.com/GoogleCloudPlatform/ios-docs-samples/tree/master/speech/Objective-C/Speech-gRPC-Streaming.

I created a static library, kept only the SpeechRecognitionService.h and SpeechRecognitionService.m files and generated the *.a fat library.

The issue

I have to generate the ApiDefinition.cs using sharpie. So I executed the command sharpie bind -sdk iphoneos11.2 -output Output -scope . [full-path-to-SpeechRecognitionService.h]. I tried some clang options but each time I have this kind of error:

Parsing 1 header files...
[full-path-to-project]/SpeechRecognitionService.h:18:9: fatal error: 
      'google/cloud/speech/v1/CloudSpeech.pbrpc.h' file not found
#import "google/cloud/speech/v1/CloudSpeech.pbrpc.h"
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Binding...
1 error generated.
Error while processing [full-path-to-project]/SpeechRecognitionService.h.

Done. Exiting with error code 1.
error: Clang failed to parse input and exited with code 1

It seems that I have to pass some clang arguments to tell where are the headers but they are not all in one folder.

How can I tell sharpie to search for headers in multiples folders?

Romain Rastel
  • 5,144
  • 2
  • 25
  • 23

1 Answers1

0

You can use *.h to match all the header files under the project folder.

For example

sharpie bind --output=InfColorPicker --namespace=InfColorPicker --sdk=[iphone-os] [full-path-to-project]/InfColorPicker/InfColorPicker/*.h

You can search this in official documentation

Community
  • 1
  • 1
ColeX
  • 14,062
  • 5
  • 43
  • 240
  • Thanks but I already tried that (even with [full-path-to-project]/**/*.h), but I still have the same issue. The import is not found. – Romain Rastel Mar 29 '18 at 09:01
  • Sorry , i misunderstood . I suggest you create this by using CocoaPods https://learn.microsoft.com/en-us/xamarin/cross-platform/macios/binding/objective-sharpie/examples/cocoapod – ColeX Mar 29 '18 at 09:08
  • No problem ;-). I didn't mention it, but I also tried this, but since googleapis is a local pod to this iOS project, and not in the cocopoads repository, the command don't find it. Edit: I also tried to bind the Xcode project, but there is an issue with the lPods libs not found :/. – Romain Rastel Mar 29 '18 at 09:15
  • Got it , but I didn't heard this (create `ApiDefinition` with header file in different folders) before. check sharpie command [here](https://learn.microsoft.com/en-us/xamarin/cross-platform/macios/binding/objective-sharpie/tools) , I think we need to keep all header file inside the same folder.. – ColeX Mar 29 '18 at 09:25
  • Ok so that means I have to refactor all the google generated code and hope for the best :/ – Romain Rastel Mar 29 '18 at 09:29
  • from [the sharpie docs](https://learn.microsoft.com/en-us/xamarin/ios/platform/binding-objective-c/walkthrough?tabs=macos): `Note that in this example we've passed *.h as a parameter, which includes all the header files in this directory - normally you should NOT do this, but instead carefully read through the header files to find the top-level .h file that references all the other relevant files, and just pass that to Objective Sharpie.` – Mando Dec 10 '19 at 22:57