Import speech recognition as sr from google cloud import speech v1p1beta1 as speech
Download 5.25 Kb. Pdf ko'rish
|
2 modul
import speech_recognition as sr from google.cloud import speech_v1p1beta1 as speech from google.cloud import translate_v2 as translate # Google Cloud-tingizdagi xizmatga ulanish uchun autentifikatsiya ma'lumotlarini o'rnating os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/your/credentials.json" # Matnni ovoz sifatida tanish recognizer = sr.Recognizer() with sr.Microphone() as source: print("Say something...") audio = recognizer.listen(source) # Ovozni matnga o'girish client = speech.SpeechClient() config = speech.RecognitionConfig( encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16, sample_rate_hertz=16000, language_code="uz-UZ", ) audio = speech.RecognitionAudio(content=audio.frame_data) response = client.recognize(config=config, audio=audio) # Tarjima qilish translate_client = translate.Client() text = response.results[0].alternatives[0].transcript result = translate_client.translate(text, target_language='en') print("Translated text: " + result['translatedText']) Download 5.25 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling