-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added ability to use in-memory files (Bytes, vec[u8]) * Removed unnecessary trait impls * Polished example
- Loading branch information
Showing
7 changed files
with
120 additions
and
39 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
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,10 @@ | ||
[package] | ||
name = "in-memory-file" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
async-openai = {path = "../../async-openai"} | ||
tokio = { version = "1.25.0", features = ["full"] } | ||
bytes = "1.5.0" |
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,3 @@ | ||
### Output | ||
|
||
> Hello, I'm David Attenborough. I'm speaking to you from my home because, like many of you, I've spent much of the last year indoors, away from friends, family, and access to the natural world. It's been a challenging few months for many of us, but the reaction to these extraordinary times has proved that when we work together, there is no limit to what we can accomplish. Today, we are experiencing environmental change as never before. And the need to take action has never been more urgent. This year, the world will gather in Glasgow for the United Nations Climate Change Conference. It's a crucial moment in our history. This could be a year for positive change for ourselves, for our planet, and for the wonderful creatures with which we share it. A year the world could remember proudly and say, we made a difference. As we make our New Year's resolutions, let's think about what each of us could do. What positive changes could we make in our own lives? So here's to a brighter year ahead. Let's make 2021 a happy New Year for all the inhabitants of our perfect planet. |
Binary file added
BIN
+4.51 MB
...y-file/audio/A Message From Sir David Attenborough A Perfect Planet BBC Earth_320kbps.mp3
Binary file not shown.
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,28 @@ | ||
use async_openai::{types::CreateTranscriptionRequestArgs, Client}; | ||
use std::error::Error; | ||
use std::fs; | ||
use async_openai::types::AudioInput; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn Error>> { | ||
let filename = "A Message From Sir David Attenborough A Perfect Planet BBC Earth_320kbps.mp3".to_string(); | ||
let file_contents = fs::read(format!("./audio/{}", filename))?; | ||
|
||
let bytes = bytes::Bytes::from(file_contents); | ||
|
||
// To pass in in-memory files, you can pass either bytes::Bytes or vec[u8] to AudioInputs, FileInputs, and ImageInputs. | ||
let audio_input = AudioInput::from_bytes(filename, bytes); | ||
|
||
let client = Client::new(); | ||
// Credits and Source for audio: https://www.youtube.com/watch?v=oQnDVqGIv4s | ||
let request = CreateTranscriptionRequestArgs::default() | ||
.file(audio_input) | ||
.model("whisper-1") | ||
.build()?; | ||
|
||
let response = client.audio().transcribe(request).await?; | ||
|
||
println!("{}", response.text); | ||
|
||
Ok(()) | ||
} |