-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from AssemblyAI/niels/add-transcribe
Add transcribe and other handwritten methods + tests
- Loading branch information
Showing
13 changed files
with
382 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -477,4 +477,4 @@ $RECYCLE.BIN/ | |
*.lnk | ||
|
||
.idea | ||
.runsettings | ||
.runsettings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using NUnit.Framework; | ||
|
||
namespace AssemblyAI.Test; | ||
|
||
[TestFixture] | ||
public class FilesClientTests | ||
{ | ||
private string _apiKey; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
// Retrieve the API key from the .runsettings file | ||
_apiKey = TestContext.Parameters.Get("ASSEMBLYAI_API_KEY"); | ||
if(string.IsNullOrEmpty(_apiKey)) throw new Exception("ASSEMBLYAI_API_KEY .runsetting parameter is not set."); | ||
} | ||
|
||
[Test] | ||
public async Task Should_Upload_File_Using_FileInfo() | ||
{ | ||
// Assuming there's a method to create a configured RawClient instance | ||
var client = new AssemblyAIClient(_apiKey); | ||
|
||
// Adjust the path to where your test file is located | ||
var testFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "nbc.mp3"); | ||
var fileInfo = new FileInfo(testFilePath); | ||
|
||
var uploadedFile = await client.Files.UploadAsync(fileInfo).ConfigureAwait(false); | ||
|
||
Assert.That(uploadedFile, Is.Not.Null); | ||
Assert.That(uploadedFile.UploadUrl, Is.Not.Null); | ||
} | ||
|
||
[Test] | ||
public async Task Should_Upload_File_Using_Stream() | ||
{ | ||
// Assuming there's a method to create a configured RawClient instance | ||
var client = new AssemblyAIClient(_apiKey); | ||
|
||
// Adjust the path to where your test file is located | ||
var testFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "nbc.mp3"); | ||
await using var fileStream = File.OpenRead(testFilePath); | ||
|
||
var uploadedFile = await client.Files.UploadAsync(fileStream).ConfigureAwait(false); | ||
|
||
Assert.That(uploadedFile, Is.Not.Null); | ||
Assert.That(uploadedFile.UploadUrl, Is.Not.Null); | ||
} | ||
} |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
using NUnit.Framework; | ||
|
||
namespace AssemblyAI.Test; | ||
|
||
[TestFixture] | ||
public class TranscriptsClientTests | ||
{ | ||
private string _apiKey; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
// Retrieve the API key from the .runsettings file | ||
_apiKey = TestContext.Parameters.Get("ASSEMBLYAI_API_KEY"); | ||
if(string.IsNullOrEmpty(_apiKey)) throw new Exception("ASSEMBLYAI_API_KEY .runsettings parameter is not set."); | ||
} | ||
|
||
[Test] | ||
public async Task Should_Submit_Using_Uri() | ||
{ | ||
// Assuming there's a method to create a configured RawClient instance | ||
var client = new AssemblyAIClient(_apiKey); | ||
|
||
var transcript = await client.Transcripts.SubmitAsync( | ||
new Uri("https://storage.googleapis.com/aai-docs-samples/nbc.mp3") | ||
).ConfigureAwait(false); | ||
|
||
Assert.That(transcript, Is.Not.Null); | ||
Assert.That(transcript.Id, Is.Not.Null); | ||
Assert.That(transcript.Status, Is.EqualTo(TranscriptStatus.Queued)); | ||
} | ||
|
||
[Test] | ||
public async Task Should_Submit_Using_Stream() | ||
{ | ||
// Assuming there's a method to create a configured RawClient instance | ||
var client = new AssemblyAIClient(_apiKey); | ||
|
||
// Adjust the path to where your test file is located | ||
var testFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "nbc.mp3"); | ||
await using var stream = File.OpenRead(testFilePath); | ||
|
||
var transcript = await client.Transcripts.SubmitAsync(stream).ConfigureAwait(false); | ||
|
||
Assert.That(transcript, Is.Not.Null); | ||
Assert.That(transcript.Id, Is.Not.Null); | ||
Assert.That(transcript.Status, Is.EqualTo(TranscriptStatus.Queued)); | ||
} | ||
|
||
[Test] | ||
public async Task Should_Submit_Using_FileInfo() | ||
{ | ||
// Assuming there's a method to create a configured RawClient instance | ||
var client = new AssemblyAIClient(_apiKey); | ||
|
||
// Adjust the path to where your test file is located | ||
var testFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "nbc.mp3"); | ||
var fileInfo = new FileInfo(testFilePath); | ||
|
||
var transcript = await client.Transcripts.SubmitAsync(fileInfo).ConfigureAwait(false); | ||
|
||
Assert.That(transcript, Is.Not.Null); | ||
Assert.That(transcript.Id, Is.Not.Null); | ||
Assert.That(transcript.Status, Is.EqualTo(TranscriptStatus.Queued)); | ||
} | ||
|
||
[Test] | ||
public async Task Should_Transcribe_Using_Uri() | ||
{ | ||
// Assuming there's a method to create a configured RawClient instance | ||
var client = new AssemblyAIClient(_apiKey); | ||
|
||
var transcript = await client.Transcripts.TranscribeAsync( | ||
new Uri("https://storage.googleapis.com/aai-docs-samples/nbc.mp3") | ||
).ConfigureAwait(false); | ||
|
||
Assert.That(transcript, Is.Not.Null); | ||
Assert.That(transcript.Id, Is.Not.Null); | ||
Assert.That(transcript.Status, Is.EqualTo(TranscriptStatus.Queued)); | ||
} | ||
|
||
[Test] | ||
public async Task Should_Transcribe_From_FileInfo() | ||
{ | ||
// Assuming there's a method to create a configured RawClient instance | ||
var client = new AssemblyAIClient(_apiKey); | ||
|
||
// Adjust the path to where your test file is located | ||
var testFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "nbc.mp3"); | ||
var fileInfo = new FileInfo(testFilePath); | ||
|
||
var transcript = await client.Transcripts.TranscribeAsync(fileInfo).ConfigureAwait(false); | ||
|
||
Assert.That(transcript, Is.Not.Null); | ||
Assert.That(transcript.Id, Is.Not.Null); | ||
Assert.That(transcript.Status, Is.EqualTo(TranscriptStatus.Completed)); | ||
} | ||
|
||
[Test] | ||
public async Task Should_Transcribe_Using_Stream() | ||
{ | ||
// Assuming there's a method to create a configured RawClient instance | ||
var client = new AssemblyAIClient(_apiKey); | ||
|
||
// Adjust the path to where your test file is located | ||
var testFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "nbc.mp3"); | ||
await using var stream = File.OpenRead(testFilePath); | ||
|
||
var transcript = await client.Transcripts.TranscribeAsync(stream).ConfigureAwait(false); | ||
|
||
Assert.That(transcript, Is.Not.Null); | ||
Assert.That(transcript.Id, Is.Not.Null); | ||
Assert.That(transcript.Status, Is.EqualTo(TranscriptStatus.Completed)); | ||
} | ||
|
||
[Test] | ||
public async Task Should_Wait_Until_Ready() | ||
{ | ||
// Assuming there's a method to create a configured RawClient instance | ||
var client = new AssemblyAIClient(_apiKey); | ||
|
||
// Adjust the path to where your test file is located | ||
var testFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "nbc.mp3"); | ||
await using var stream = File.OpenRead(testFilePath); | ||
|
||
var transcript = await client.Transcripts.SubmitAsync(stream).ConfigureAwait(false); | ||
transcript = await client.Transcripts.WaitUntilReady(transcript.Id).ConfigureAwait(false); | ||
|
||
Assert.That(transcript, Is.Not.Null); | ||
Assert.That(transcript.Id, Is.Not.Null); | ||
Assert.That(transcript.Status, Is.EqualTo(TranscriptStatus.Completed)); | ||
} | ||
|
||
[Test] | ||
public async Task Should_Paginate_Transcripts() | ||
{ | ||
// Assuming there's a method to create a configured RawClient instance | ||
var client = new AssemblyAIClient(_apiKey); | ||
var transcriptPage = await client.Transcripts.ListAsync().ConfigureAwait(false); | ||
Assert.That(transcriptPage, Is.Not.Null); | ||
Assert.That(transcriptPage.PageDetails.PrevUrl, Is.Not.Null); | ||
Assert.That(transcriptPage.Transcripts, Is.Not.Empty); | ||
|
||
var prevPage = await client.Transcripts.ListAsync(transcriptPage.PageDetails.PrevUrl); | ||
Assert.That(transcriptPage, Is.Not.Null); | ||
Assert.That(transcriptPage.PageDetails.NextUrl, Is.Not.Null); | ||
Assert.That(transcriptPage.Transcripts, Is.Not.Empty); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RunSettings> | ||
<TestRunParameters> | ||
<Parameter name="ASSEMBLYAI_API_KEY" value="" /> | ||
<Parameter name="TEST_TRANSCRIPT_ID" value="" /> | ||
</TestRunParameters> | ||
</RunSettings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Net.Http; | ||
using System.Text.Json; | ||
using AssemblyAI; | ||
using AssemblyAI.Core; | ||
|
||
#nullable enable | ||
|
||
namespace AssemblyAI; | ||
|
||
public partial class FilesClient | ||
{ | ||
/// <summary> | ||
/// Upload a media file to AssemblyAI's servers. | ||
/// </summary> | ||
public async Task<UploadedFile> UploadAsync(FileInfo audioFile) | ||
{ | ||
using var audioFileStream = audioFile.OpenRead(); | ||
return await UploadAsync(audioFileStream).ConfigureAwait(false); | ||
} | ||
} |
Oops, something went wrong.