Repository navigation
fix(sync): accept file objects that have no path for a name - #268
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
SyncTranscriber.transcribe() read the audio part's filename from the file object's name attribute and passed it to os.path.basename(). Anonymous files such as tempfile.TemporaryFile() report a file descriptor (an int) as their name, so the call raised TypeError. Use the name only when it is a str, as the streaming path already does.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SyncTranscriber.transcribe()andAsyncSyncTranscriber.transcribe()read the audio part's filename from the file object'snameattribute and pass it toos.path.basename(). Anonymous files, such as the result oftempfile.TemporaryFile()on POSIX, report a file descriptor (anint) as their name, so the call raisesTypeError: expected str, bytes or os.PathLike object, not int. The streaming path,stream_filename()and the Dictationresolve_source()already use the name only when it is astr.Changes
assemblyai/_audio.py: use the file object'snameonly when it is a non-emptystr. Otherwise the audio is sent under the default filename and Content-Type.tests/unit/test_sync.py: add a test that transcribes atempfile.TemporaryFile()and checks the request body.Testing
Without the source change the new test fails with the
TypeError. With the change, all 186 tests in these files pass.