Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Swimburger committed Aug 28, 2024
2 parents ba51d4e + 6101e6a commit 4939810
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 80 deletions.
3 changes: 2 additions & 1 deletion src/AssemblyAI/AssemblyAIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
using AssemblyAI.Realtime;
using AssemblyAI.Transcripts;


namespace AssemblyAI;

/// <summary>
/// The client to interact with the AssemblyAI API.
/// </summary>
public partial class AssemblyAIClient
public class AssemblyAIClient
{
/// <inheritdoc cref="FilesClient"/>
public FilesClient Files { get; private init; }
Expand Down
2 changes: 1 addition & 1 deletion src/AssemblyAI/Core/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace AssemblyAI.Core;

internal static class Extensions
{
public static string Stringify(this Enum value)
internal static string Stringify(this Enum value)
{
var field = value.GetType().GetField(value.ToString());
var attribute = (EnumMemberAttribute)
Expand Down
1 change: 1 addition & 0 deletions src/AssemblyAI/DependencyInjectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
// ReSharper disable UnusedMember.Global

namespace AssemblyAI;

Expand Down
34 changes: 28 additions & 6 deletions src/AssemblyAI/Files/ExtendedFilesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@ public partial class FilesClient
/// </summary>
/// <param name="audioFile">The local file to upload</param>
/// <param name="options">The HTTP request options</param>
public async Task<UploadedFile> UploadAsync(FileInfo audioFile, RequestOptions? options = null)
/// <param name="cancellationToken"></param>
/// <returns>File uploaded to AssemblyAI</returns>
public async Task<UploadedFile> UploadAsync(
FileInfo audioFile,
RequestOptions? options = null,
CancellationToken cancellationToken = default
)
{
#if NET6_0_OR_GREATER
await using var audioFileStream = audioFile.OpenRead();
#else
using var audioFileStream = audioFile.OpenRead();
return await UploadAsync(audioFileStream, options).ConfigureAwait(false);
#endif

return await UploadAsync(audioFileStream, options, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -22,12 +33,23 @@ public async Task<UploadedFile> UploadAsync(FileInfo audioFile, RequestOptions?
/// <param name="stream">The file stream to upload</param>
/// <param name="disposeStream">Dispose the stream ASAP</param>
/// <param name="options">The HTTP request options</param>
public async Task<UploadedFile> UploadAsync(Stream stream, bool disposeStream, RequestOptions? options = null)
/// <param name="cancellationToken"></param>
/// <returns>File uploaded to AssemblyAI</returns>
public async Task<UploadedFile> UploadAsync(
Stream stream,
bool disposeStream,
RequestOptions? options = null,
CancellationToken cancellationToken = default
)
{
if (!disposeStream) return await UploadAsync(stream, options).ConfigureAwait(false);
if (!disposeStream) return await UploadAsync(stream, options, cancellationToken).ConfigureAwait(false);
#if NET6_0_OR_GREATER
await using (stream)
#else
using (stream)
#endif
{
return await UploadAsync(stream, options).ConfigureAwait(false);
return await UploadAsync(stream, options, cancellationToken).ConfigureAwait(false);
}
}
}
}
6 changes: 4 additions & 2 deletions src/AssemblyAI/Realtime/ExtendedRealtimeClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ReSharper disable UnusedMember.Global

namespace AssemblyAI.Realtime;

/// <summary>
Expand All @@ -12,12 +13,13 @@ public partial class RealtimeClient
/// </summary>
public Task<RealtimeTemporaryTokenResponse> CreateTemporaryTokenAsync(
int expiresIn,
RequestOptions? options = null
RequestOptions? options = null,
CancellationToken cancellationToken = default
)
=> CreateTemporaryTokenAsync(new CreateRealtimeTemporaryTokenParams
{
ExpiresIn = expiresIn
}, options);
}, options, cancellationToken);

/// <summary>
/// Create a real-time transcriber
Expand Down
Loading

0 comments on commit 4939810

Please sign in to comment.