技能标识:senseaudio-weather-broadcast
Fetch weather data and generate a spoken weather broadcast using SenseAudio TTS.
Fetch real-time weather data and generate a natural-sounding weather broadcast audio using SenseAudio TTS.
获取实时天气数据,并使用 SenseAudio TTS 生成自然流畅的天气播报音频。
bash
Free weather service, no API key required. / 免费天气服务,无需 API 密钥。
bash
Format codes / 格式代码:
Options / 选项:
Free JSON API for programmatic use. / 免费 JSON API,适合程序化使用。
bash
python
import requests
import os
SENSEAUDIOAPIKEY = os.environ.get(SENSEAUDIOAPIKEY)
TTSURL = https://api.senseaudio.cn/v1/t2av2
def get_weather(city: str, lang: str = zh) -> str:
Fetch weather from wttr.in / 从 wttr.in 获取天气
url = fhttps://wttr.in/{city}?format=%l:+%c+%t+%h+%w&lang={lang}
resp = requests.get(url, timeout=10)
return resp.text.strip()
def generatebroadcasttext(weather: str, lang: str = zh) -> str:
Generate broadcast script / 生成播报文本
if lang == zh:
return f天气播报:{weather}。
else:
return fWeather report: {weather}.
def texttospeech(text: str, outputfile: str = weatherbroadcast.mp3, voiceid: str = male0004_a):
Convert text to speech using SenseAudio TTS / 使用 SenseAudio TTS 转换文本为语音
headers = {
Authorization: fBearer {SENSEAUDIOAPIKEY},
Content-Type: application/json
}
payload = {
model: SenseAudio-TTS-1.0,
text: text,
stream: False,
voice_setting: {
voiceid: voiceid,
speed: 0.95,
vol: 1.0,
pitch: 0
},
audio_setting: {
format: mp3,
sample_rate: 32000
}
}
resp = requests.post(TTS_URL, json=payload, headers=headers, timeout=30)
result = resp.json()
if result.get(data) and result[data].get(audio):
audio_bytes = bytes.fromhex(result[data][audio])
with open(output_file, wb) as f:
f.write(audio_bytes)
print(fAudio saved: {output_file})
print(fDuration: {result[extrainfo][audiolength]}ms)
return output_file
else:
raise Exception(fTTS failed: {result.get(baseresp, {}).get(statusmsg, Unknown error)})
def weatherbroadcast(city: str, outputfile: str = weather_broadcast.mp3, lang: str = zh):
Main function: fetch weather and generate broadcast / 主函数:获取天气并生成播报
print(fFetching weather for {city}...)
weather = get_weather(city, lang)
print(fWeather: {weather})
broadcasttext = generatebroadcast_text(weather, lang)
print(fBroadcast text: {broadcast_text})
print(Generating audio...)
return texttospeech(broadcasttext, outputfile)
if name == main:
# Example usage / 示例用法
weatherbroadcast(Beijing, beijingweather.mp3, zh)
# weatherbroadcast(London, londonweather.mp3, en)
| Voice ID | Description / 描述 | Style / 风格 |
|---|---|---|
| male0004a | Warm male / 温暖男声 | News anchor / 新闻主播 |
| female0001a |
See SenseAudio Voice List for all available voices.
查看 SenseAudio 音色列表 获取所有可用音色。
| Parameter / 参数 | Type / 类型 | Default / 默认 | Range / 范围 | Description / 描述 |
|---|---|---|---|---|
| speed | float | 1.0 | 0.5-2.0 | Speech rate / 语速 |
| vol |
| Format / 格式 | Sample Rate / 采样率 | Use Case / 适用场景 |
|---|---|---|
| mp3 | 32000 | General use / 通用 |
| wav |
以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:
帮我安装 SkillHub 和 weather-broadcast-1776075363 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 weather-broadcast-1776075363 技能
skillhub install weather-broadcast-1776075363
文件大小: 4.04 KB | 发布时间: 2026-4-15 14:54