File size: 1,164 Bytes
44a1d60 | 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 | import requests
import whisper
import tempfile
# Whisper model (STT)
whisper_model = whisper.load_model("base")
def speech_to_text(audio):
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
tmp.write(audio)
result = whisper_model.transcribe(tmp.name)
return result["text"]
# Live Currency API
def get_currency_info(country):
try:
response = requests.get(f"https://restcountries.com/v3.1/name/{country}")
data = response.json()[0]
currency_code = list(data['currencies'].keys())[0]
return f"{currency_code} - {data['currencies'][currency_code]['name']}"
except:
return "Currency info unavailable."
# Weather via OpenWeatherMap (You must set your API key)
def get_weather(city, api_key="YOUR_OPENWEATHERMAP_API_KEY"):
try:
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
res = requests.get(url).json()
temp = res['main']['temp']
condition = res['weather'][0]['description']
return f"Weather in {city}: {temp}°C, {condition}"
except:
return "Weather info unavailable."
|