forked from openai/openai-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeech_to_text.py
More file actions
executable file
·40 lines (29 loc) · 953 Bytes
/
speech_to_text.py
File metadata and controls
executable file
·40 lines (29 loc) · 953 Bytes
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
#!/usr/bin/env rye run python
import asyncio
from aimlapi import AsyncAIMLAPI
from openai.helpers import Microphone
# gets AIML_API_KEY from your environment variables
aimlapi = AsyncAIMLAPI()
# TODO: FIX FOR AIMLAPI + REMOVE COMMENTS
async def main() -> None:
print("Recording for the next 10 seconds...")
recording = await Microphone(timeout=10).record()
print("Recording complete")
result = await aimlapi.audio.transcriptions.create(
model="#g1_whisper-large", # our STT model ID
file=recording, # bytes-like object from Microphone
)
transcript = (
result.get("result", {})
.get("results", {})
.get("channels", [{}])[0]
.get("alternatives", [{}])[0]
.get("transcript")
)
if transcript:
print("Transcription:")
print(transcript)
else:
print("Full STT response:", result)
if __name__ == "__main__":
asyncio.run(main())