Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
import torch
|
|
|
|
|
2 |
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
3 |
from datasets import load_dataset
|
4 |
from googletrans import Translator
|
@@ -45,13 +47,19 @@ async def process_audio(file: UploadFile = File(...)):
|
|
45 |
content = await file.read()
|
46 |
saved_file.write(content)
|
47 |
|
48 |
-
#
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
# EN
|
53 |
-
result = pipe(
|
54 |
-
hasil = result["text"]
|
55 |
|
56 |
# ID
|
57 |
detect = detect_google(hasil)
|
|
|
1 |
import torch
|
2 |
+
import torchaudio
|
3 |
+
import numpy as np
|
4 |
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
5 |
from datasets import load_dataset
|
6 |
from googletrans import Translator
|
|
|
47 |
content = await file.read()
|
48 |
saved_file.write(content)
|
49 |
|
50 |
+
# Load audio file using torchaudio
|
51 |
+
waveform, sample_rate = torchaudio.load(file_location)
|
52 |
+
|
53 |
+
# Ensure the waveform is a 1D array
|
54 |
+
waveform = waveform[0] if waveform.size(0) > 1 else waveform
|
55 |
+
|
56 |
+
# ASR
|
57 |
+
original = pipe(waveform.numpy(), sampling_rate=sample_rate)
|
58 |
+
original_version = original[0]["text"]
|
59 |
|
60 |
# EN
|
61 |
+
result = pipe(waveform.numpy(), generate_kwargs={"task": "translate"}, sampling_rate=sample_rate)
|
62 |
+
hasil = result[0]["text"]
|
63 |
|
64 |
# ID
|
65 |
detect = detect_google(hasil)
|