|
from googleapiclient.discovery import build |
|
from google.oauth2 import service_account |
|
from googleapiclient.http import MediaFileUpload |
|
import pdb |
|
|
|
import gradio as gr |
|
|
|
|
|
credentials_file = "./src/peerless-window-254907-b386b71c0d99.json" |
|
|
|
|
|
api_version = 'v3' |
|
|
|
|
|
credentials = service_account.Credentials.from_service_account_file( |
|
credentials_file, scopes=['https://www.googleapis.com/auth/drive']) |
|
service = build('drive', api_version, credentials=credentials) |
|
|
|
|
|
import gradio as gr |
|
from transformers import pipeline |
|
import numpy as np |
|
import librosa |
|
import torchaudio |
|
|
|
import datetime |
|
|
|
def generate_now_time_wav(): |
|
|
|
current_time = datetime.datetime.now() |
|
|
|
|
|
time_string = current_time.strftime("%Y-%m-%d_%H-%M-%S") |
|
|
|
|
|
wavfile_name = f"audio_{time_string}.wav" |
|
return wavfile_name |
|
|
|
|
|
|
|
def transcribe(audio_path): |
|
if audio_path == None: |
|
print("using ref audio as eval audio since it's empty") |
|
|
|
wav, sr = torchaudio.load(audio_path) |
|
if wav.shape[0] != 1: |
|
wav = wav[0, :] |
|
print(wav.shape) |
|
|
|
name = generate_now_time_wav() |
|
|
|
media = MediaFileUpload(audio_path, mimetype='audio/wav') |
|
request = service.files().create( |
|
media_body=media, |
|
body={'name': name} |
|
) |
|
response = request.execute() |
|
|
|
return response.get('id') |
|
|
|
demo = gr.Interface( |
|
fn = transcribe, |
|
inputs = gr.Audio(source="microphone", type='filepath'), |
|
outputs = "text", |
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
demo.launch() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|