File size: 1,262 Bytes
a18c706
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from datetime import datetime
import tensorflow as tf
from tensorflow.keras.models import load_model
import numpy as np
import librosa

# Load pre-trained models
speech_to_text_model = load_model('speech_to_text_model.h5')
translation_model = load_model('translation_model.h5')

def preprocess_audio(file_path):
    # Load and preprocess the audio file
    audio, sr = librosa.load(file_path, sr=16000)
    mfccs = librosa.feature.mfcc(y=audio, sr=sr, n_mfcc=13)
    return np.expand_dims(mfccs, axis=0)

def translate_speech_to_text(audio_file):
    # Preprocess the audio file
    audio_features = preprocess_audio(audio_file)
    
    # Predict text from audio
    predicted_text = speech_to_text_model.predict(audio_features)
    
    # Translate text
    translated_text = translation_model.predict([predicted_text])
    
    return translated_text

def is_after_six_pm():
    current_time = datetime.now()
    return current_time.hour >= 18

def main(audio_file):
    if is_after_six_pm():
        translated_text = translate_speech_to_text(audio_file)
        print("Translated Text:", translated_text)
    else:
        print("Service available only after 6 PM IST.")

# Example usage
audio_file_path = 'path/to/your/audiofile.wav'
main(audio_file_path)