Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,7 +1,4 @@
|
|
| 1 |
import torch
|
| 2 |
-
import torchaudio
|
| 3 |
-
import wave
|
| 4 |
-
import numpy as np
|
| 5 |
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
| 6 |
from datasets import load_dataset
|
| 7 |
from googletrans import Translator
|
|
@@ -45,22 +42,15 @@ async def process_audio(file: UploadFile = File(...)):
|
|
| 45 |
file_location = save_directory / file.filename
|
| 46 |
|
| 47 |
with open(file_location, "wb") as saved_file:
|
| 48 |
-
|
| 49 |
-
saved_file.write(content)
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
# Ensure the waveform is a single-channel array
|
| 55 |
-
waveform = waveform[0] if waveform.size(0) > 1 else waveform
|
| 56 |
-
|
| 57 |
-
# ASR
|
| 58 |
-
original = pipe(waveform.numpy())
|
| 59 |
-
original_version = original[0]["text"]
|
| 60 |
|
| 61 |
# EN
|
| 62 |
-
result = pipe(
|
| 63 |
-
hasil = result[
|
| 64 |
|
| 65 |
# ID
|
| 66 |
detect = detect_google(hasil)
|
|
|
|
| 1 |
import torch
|
|
|
|
|
|
|
|
|
|
| 2 |
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
| 3 |
from datasets import load_dataset
|
| 4 |
from googletrans import Translator
|
|
|
|
| 42 |
file_location = save_directory / file.filename
|
| 43 |
|
| 44 |
with open(file_location, "wb") as saved_file:
|
| 45 |
+
saved_file.write(file.file.read())saved_file.write(content)
|
|
|
|
| 46 |
|
| 47 |
+
# JP
|
| 48 |
+
original = pipe(file_location)
|
| 49 |
+
original_version = original["text"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
# EN
|
| 52 |
+
result = pipe(file_location, generate_kwargs={"task": "translate"})
|
| 53 |
+
hasil = result["text"]
|
| 54 |
|
| 55 |
# ID
|
| 56 |
detect = detect_google(hasil)
|