Merge pull request #1131 from KPatr1ck/video_demo
[Demo]Add automatic_video_subtitiles demo.pull/1139/head
commit
5b650b9792
@ -0,0 +1,50 @@
|
||||
# Automatic Video Subtitiles
|
||||
|
||||
## Introduction
|
||||
Automatic video subtitiles can generate subtitiles from a specific video by using Automatic Speech Recognition (ASR) system.
|
||||
|
||||
This demo is an implementation to automatic video subtitiles from a video file. It can be done by a single command or a few lines in python using `PaddleSpeech`.
|
||||
|
||||
## Usage
|
||||
### 1. Installation
|
||||
```bash
|
||||
pip install paddlespeech
|
||||
```
|
||||
|
||||
### 2. Prepare Input
|
||||
Get a video file with speech of the specific language:
|
||||
```bash
|
||||
wget -c https://paddlespeech.bj.bcebos.com/demos/asr_demos/subtitle_demo1.mp4
|
||||
```
|
||||
|
||||
Extract `.wav` with one channel and 16000 sample rate from the video:
|
||||
```bash
|
||||
ffmpeg -i subtitle_demo1.mp4 -ac 1 -ar 16000 -vn input.wav
|
||||
```
|
||||
|
||||
|
||||
### 3. Usage
|
||||
|
||||
- Python API
|
||||
```python
|
||||
import paddle
|
||||
from paddlespeech.cli import ASRExecutor, TextExecutor
|
||||
|
||||
asr_executor = ASRExecutor()
|
||||
text_executor = TextExecutor()
|
||||
|
||||
text = asr_executor(
|
||||
audio_file='input.wav',
|
||||
device=paddle.get_device())
|
||||
result = text_executor(
|
||||
text=text,
|
||||
task='punc',
|
||||
model='ernie_linear_p3_wudao',
|
||||
device=paddle.get_device())
|
||||
print('Text Result: \n{}'.format(result))
|
||||
```
|
||||
Output:
|
||||
```bash
|
||||
Text Result:
|
||||
当我说我可以把三十年的经验变成一个准确的算法,他们说不可能。当我说我们十个人就能实现对十九个城市变电站七乘二十四小时的实时监管,他们说不可能。
|
||||
```
|
@ -0,0 +1,43 @@
|
||||
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import argparse
|
||||
import os
|
||||
|
||||
import paddle
|
||||
|
||||
from paddlespeech.cli import ASRExecutor
|
||||
from paddlespeech.cli import TextExecutor
|
||||
|
||||
# yapf: disable
|
||||
parser = argparse.ArgumentParser(__doc__)
|
||||
parser.add_argument("--input", type=str, required=True)
|
||||
parser.add_argument("--device", type=str, default=paddle.get_device())
|
||||
args = parser.parse_args()
|
||||
# yapf: enable
|
||||
|
||||
if __name__ == "__main__":
|
||||
asr_executor = ASRExecutor()
|
||||
text_executor = TextExecutor()
|
||||
|
||||
text = asr_executor(
|
||||
audio_file=os.path.abspath(os.path.expanduser(args.input)),
|
||||
device=args.device)
|
||||
result = text_executor(
|
||||
text=text,
|
||||
task='punc',
|
||||
model='ernie_linear_p3_wudao',
|
||||
device=args.device)
|
||||
|
||||
print('ASR Result: \n{}'.format(text))
|
||||
print('Text Result: \n{}'.format(result))
|
@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
video_url=https://paddlespeech.bj.bcebos.com/demos/asr_demos/subtitle_demo1.mp4
|
||||
video_file=$(basename ${video_url})
|
||||
audio_file=$(echo ${video_file} | awk -F'.' '{print $1}').wav
|
||||
num_channels=1
|
||||
sr=16000
|
||||
|
||||
# Download video
|
||||
if [ ! -f ${video_file} ]; then
|
||||
wget -c ${video_url}
|
||||
fi
|
||||
|
||||
# Extract audio from video
|
||||
if [ ! -f ${audio_file} ]; then
|
||||
ffmpeg -i ${video_file} -ac ${num_channels} -ar ${sr} -vn ${audio_file}
|
||||
fi
|
||||
|
||||
python -u recognize.py --input ${audio_file}
|
||||
exit 0
|
Loading…
Reference in new issue