Skip to content

Commit

Permalink
[AVFoundation] Obsolete AVSpeechSynthesizer.WriteUtteranceAsync. Fixes
Browse files Browse the repository at this point in the history
…xamarin#20338.

The callback may be called multiple times, which means the async version won't
work correctly.

So obsolete and hide the Async binding for now, and remove in XAMCORE_5_0.

References:
* https://discord.com/channels/732297728826277939/732297808148824115/1219903715939582022
* https://developer.apple.com/documentation/avfaudio/avspeechsynthesizer/3141659-writeutterance?language=objc

Fixes xamarin#20338.
  • Loading branch information
rolfbjarne committed Mar 20, 2024
1 parent bb775d0 commit dcb828e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/AVFoundation/AVSpeechSynthesizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Versioning;
using System.Threading.Tasks;

using ObjCRuntime;

#nullable enable

namespace AVFoundation {

public partial class AVSpeechSynthesizer {
#if !XAMCORE_5_0
#if NET
[SupportedOSPlatform ("tvos13.0")]
[SupportedOSPlatform ("ios13.0")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
#endif
[BindingImpl (BindingImplOptions.Optimizable)]
[Obsolete ("Do not use this API, it doesn't work correctly. Use the non-Async version (WriteUtterance) instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public unsafe virtual Task<AVAudioBuffer> WriteUtteranceAsync (AVSpeechUtterance utterance)
{
var tcs = new TaskCompletionSource<AVAudioBuffer> ();
WriteUtterance(utterance, (obj_) => {
tcs.SetResult (obj_!);
});
return tcs.Task;
}
#endif
}
}
1 change: 0 additions & 1 deletion src/avfoundation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14530,7 +14530,6 @@ interface AVSpeechSynthesizer {
[Export ("speakUtterance:")]
void SpeakUtterance (AVSpeechUtterance utterance);

[Async]
[Watch (6, 0), TV (13, 0), iOS (13, 0)]
[MacCatalyst (13, 1)]
[Export ("writeUtterance:toBufferCallback:")]
Expand Down
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ AVFOUNDATION_SOURCES = \
AVFoundation/AVPlayerLayer.cs \
AVFoundation/AVPlayerViewController.cs \
AVFoundation/AVSampleBufferExtensions.cs \
AVFoundation/AVSpeechSynthesizer.cs \
AVFoundation/AVTextStyleRule.cs \
AVFoundation/Events.cs \
AVFoundation/AVPlayerLooper.cs \
Expand Down

0 comments on commit dcb828e

Please sign in to comment.