Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit 3c79663

Browse files
committed
iOS appears to work although simulator not hearing speech
1 parent fe41c7f commit 3c79663

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

WebServices/CognitiveSpeechService/CognitiveSpeechService/CognitiveSpeechService.iOS/CognitiveSpeechService.iOS.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<ItemGroup>
6363
<Compile Include="Main.cs" />
6464
<Compile Include="AppDelegate.cs" />
65+
<Compile Include="Services\iOSMicrophoneService.cs" />
6566
<None Include="Entitlements.plist" />
6667
<None Include="Info.plist" />
6768
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -120,6 +121,9 @@
120121
<Reference Include="System.Numerics.Vectors" />
121122
</ItemGroup>
122123
<ItemGroup>
124+
<PackageReference Include="Microsoft.CognitiveServices.Speech">
125+
<Version>1.8.0</Version>
126+
</PackageReference>
123127
<PackageReference Include="Xamarin.Forms" Version="4.2.0.709249" />
124128
<PackageReference Include="Xamarin.Essentials" Version="1.2.0" />
125129
</ItemGroup>

WebServices/CognitiveSpeechService/CognitiveSpeechService/CognitiveSpeechService.iOS/Info.plist

+2
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,7 @@
3434
<string>CognitiveSpeechService</string>
3535
<key>XSAppIconAssets</key>
3636
<string>Assets.xcassets/AppIcon.appiconset</string>
37+
<key>NSMicrophoneUsageDescription</key>
38+
<string>Voice transcription requires microphone access</string>
3739
</dict>
3840
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Threading.Tasks;
2+
using AVFoundation;
3+
using CognitiveSpeechService.iOS.Services;
4+
using CognitiveSpeechService.Services;
5+
using Xamarin.Forms;
6+
7+
[assembly: Dependency(typeof(iOSMicrophoneService))]
8+
namespace CognitiveSpeechService.iOS.Services
9+
{
10+
public class iOSMicrophoneService : IMicrophoneService
11+
{
12+
TaskCompletionSource<bool> tcsPermissions;
13+
14+
public Task<bool> GetPermissionAsync()
15+
{
16+
tcsPermissions = new TaskCompletionSource<bool>();
17+
RequestMicPermission();
18+
return tcsPermissions.Task;
19+
}
20+
21+
public void OnRequestPermissionResult(bool isGranted)
22+
{
23+
tcsPermissions.TrySetResult(isGranted);
24+
}
25+
26+
void RequestMicPermission()
27+
{
28+
var session = AVAudioSession.SharedInstance();
29+
session.RequestRecordPermission((granted) =>
30+
{
31+
tcsPermissions.TrySetResult(granted);
32+
});
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)