How can we directly use a video (mp4) for transcribe()
in code??
#1572
Unanswered
Shivansh-yadav13
asked this question in
Q&A
Replies: 3 comments 1 reply
-
Hopefully this discussion here is what you need - and note this comment |
Beta Was this translation helpful? Give feedback.
0 replies
-
The solution provided def load_audio(file: (str, bytes), sr: int = 16000):
"""
Open an audio file and read as mono waveform, resampling as necessary
Parameters
----------
file: (str, bytes)
The audio file to open or bytes of audio file
sr: int
The sample rate to resample the audio if necessary
Returns
-------
A NumPy array containing the audio waveform, in float32 dtype.
"""
if isinstance(file, bytes):
inp = file
file = 'pipe:'
else:
inp = None
try:
# This launches a subprocess to decode audio while down-mixing and resampling as necessary.
# Requires the ffmpeg CLI and `ffmpeg-python` package to be installed.
out, _ = (
ffmpeg.input(file, threads=0)
.output("-", format="s16le", acodec="pcm_s16le", ac=1, ar=sr)
.run(cmd="ffmpeg", capture_stdout=True, capture_stderr=True, input=inp)
)
except ffmpeg.Error as e:
raise RuntimeError(f"Failed to load audio: {e.stderr.decode()}") from e Does not work for video bytes
|
Beta Was this translation helpful? Give feedback.
1 reply
-
@glangford try:
# This launches a subprocess to decode audio while down-mixing and resampling as necessary.
# Requires the ffmpeg CLI and `ffmpeg-python` package to be installed.
out, _ = (
ffmpeg.input(file, threads=0)
.output("-", format="s16le", acodec="pcm_s16le", ac=1, ar=sr, vn=True) #here
.run(cmd="ffmpeg", capture_stdout=True, capture_stderr=True, input=inp)
) but I got this
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using NextJS to send a video file to my FAST API server,
the server receives it in
bytes
and I don't want to save the file and then use it to transcribe.Is there a way to transcribe directly from code without saving file?
Beta Was this translation helpful? Give feedback.
All reactions