問題の発端
Pollinations APIを使用している際、Text-to-Speechの使用例は提供されていたものの、Speech-to-Textについては「openai-audio モデルを使用して取得できる」と簡単に説明されただけでした。そのため、具体的なコード例を求めてAIに問い合わせを行いました。
各AIモデルのパフォーマンス
DeepSeek
DeepSeekからの応答は完全に誤りであり、実行可能ではありませんでした。
ChatGPT
import requests
def transcribe_audio(file_path):
url = "https://text.pollinations.ai/openai"
files = {
"file": open(file_path, "rb")
}
data = {
"model": "openai-audio"
}
response = requests.post(url, data=data, files=files)
if response.status_code == 200:
return response.json()
else:
raise Exception(f"リクエスト失敗: {response.status_code}, {response.text}")
if __name__ == "__main__":
audio_file = "./Welcome to Pollinations.mp3"
try:
result = transcribe_audio(audio_file)
print("転写結果:", result)
except Exception as e:
print("エラー:", e)
ChatGPTからのコードは形式的には正しいですが、音声認識機能は動作しませんでした。
Kimi
import requests
import json
def transcribe_audio(file_path):
with open(file_path, "rb") as audio_file:
messages = [
{"role": "user", "content": "この音声を転写してください"}
]
url = "https://text.pollinations.ai/"
response = requests.post(
url,
data={
"model": "openai-audio",
"messages": json.dumps(messages)
},
files={"file": audio_file}
)
if response.status_code == 200:
transcription = response.json()
print("転写:", transcription.get("text"))
else:
print("音声の転写に失敗しました。ステータスコード:", response.status_code)
print("レスポンス:", response.text)
transcribe_audio("./Welcome to Pollinations.mp3")
Kimiからのコードはパラメータの形式が間違っていて、修正しても正確なコードにはなりませんでした。
Mistral
import requests
def speech_to_text(audio_file_path):
url = "https://text.pollinations.ai/openai"
headers = {
"Content-Type": "application/json"
}
data = {
"model": "openai-audio",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "次の音声を転写してください:"
},
{
"type": "audio_url",
"audio_url": {
"url": audio_file_path
}
}
]
}
]
}
response = requests.post(url, headers=headers, json=data)
return response.json()
audio_url = "https://www.runoob.com/try/demo_source/horse.mp3"
transcription = speech_to_text(audio_url)
print(transcription)
Mistralからのコードはオーディオパラメータの形式が間違っており、base64形式でデータを送信する必要がありました。
Claude 3.7 Sonnet
Claude 3.7 SonnetからのコードもAPI部分から間違っており、実行可能ではありませんでした。
実行可能なコード
import base64
import requests
def analyze_audio(audio_file_path):
with open(audio_file_path, "rb") as audio_file:
audio_data = audio_file.read()
audio_base64 = base64.b64encode(audio_data).decode("utf-8")
response = requests.post('https://text.pollinations.ai/openai', json={
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "この音声は何ですか?"},
{
"type": "input_audio",
"input_audio": {
"data": audio_base64,
"format": "mp3"
}
}
]
}
],
"model": "openai-audio"
})
return response.json()
result = analyze_audio("./Welcome to Pollinations.mp3")
print(result['choices'][0]['message']['content'])
まとめ
5つのAIツールを使用してこの問題を解決しようとしましたが、結果は以下のようなものでした:
- DeepSeekとClaude 3.7 Sonnetは完全に誤ったコードを提供し、APIの設定さえ間違っていました。
- ChatGPTとKimiは正しいAPIとモデル設定を提供しましたが、パラメータの形式が間違っていました。
- Mistralは約70%の部分が正しく、オーディオパラメータの形式以外は正確でした。
AIは非常に強力ですが、全ての問題を完璧に解決できるわけではありません。多くの問題においてまだ改善の余地があります。