Spaces:
Sleeping
Sleeping
# import gradio as gr | |
# def greet(name): | |
# return "Hello " + name + "!!" | |
# iface = gr.Interface(fn=greet, inputs="text", outputs="text") | |
# iface.launch(share=True) | |
# -*- coding: utf-8 -*- | |
"""gradio.ipynb | |
Automatically generated by Colaboratory. | |
Original file is located at | |
https://colab.research.google.com/drive/1_GWRGRVb3znpFoAUO_7jj36vZG2FseJi | |
""" | |
# import os | |
# os.system('pip install wit') | |
# os.system('pip install scipy') | |
# !pip install gradio | |
# !pip install wit | |
# !pip install scipy | |
import gradio as gr | |
from wit import Wit | |
import numpy as np | |
import io | |
from scipy.io.wavfile import write | |
def is_enrolled_voice(name, wave_file): | |
return True | |
def STT(wave_file): | |
# Wit.ai API μ°κ²°μ μν ν΄λΌμ΄μΈνΈ μμ± | |
wit_api_key = "HBAX6TJEDWRKUIUA62MFQZCXYG4BKQBQ" | |
wit_url = "https://api.wit.ai/speech" | |
wit_client = Wit(wit_api_key) | |
# μμ± νμΌμμ ν μ€νΈ μΆμΆ | |
print("STT μν μ ") | |
print("wave_file μ νμ :", type(wave_file)) | |
print(wave_file) | |
sample_rate, data = wave_file | |
# μ κ·ν λ° 16λΉνΈλ‘ λ³ν | |
scaled_data = (data / np.max(np.abs(data)) * 32767).astype(np.int16) | |
# λ³μμ .wav νμΌ λ°μ΄ν° μ μ₯ | |
wav_data = io.BytesIO() | |
write(wav_data, sample_rate, scaled_data) | |
response = wit_client.speech(wav_data, headers={'Content-Type': 'audio/wav'}) | |
print("STT μν ν") | |
print(response) | |
print(type(response)) | |
# μΆμΆλ ν μ€νΈ νμΈ | |
if 'text' in response: | |
return response['text'] | |
else: | |
return "μΆμΆλ ν μ€νΈ μμ!" | |
def function(name, wave_file): | |
is_enrolled = is_enrolled_voice(name, wave_file) | |
if is_enrolled: # λ±λ‘λ λͺ©μλ¦¬μΈ κ²½μ° STT | |
print("λ±λ‘λ λͺ©μ리 μ λλ€!") | |
output_text = STT(wave_file) | |
return output_text | |
else: | |
return "λ±λ‘λμ§ μμ λͺ©μ리μ λλ€!" | |
def main(): | |
demo = gr.Interface( | |
function, | |
inputs=["text", "audio"], | |
outputs=["text"] | |
) | |
demo.launch(debug=True, share=True) | |
if __name__ == '__main__': | |
main() |