-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwhispertest.py
76 lines (57 loc) · 1.83 KB
/
whispertest.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import discord
import wave
import io
import requests
from openai import OpenAI
from config import PHOTOBOT_KEY
from discord import FFmpegPCMAudio
import asyncio
from pathlib import Path
client = OpenAI()
intents = discord.Intents.all()
intents.message_content = True # Required to read message content
# bot = discord.Bot(intents=intents)
# @bot.command()
# async def join(ctx):
# if ctx.author.voice is None:
# await ctx.respond("You need to join a voice channel first.")
# return
# channel = ctx.author.voice.channel
# if ctx.voice_client is not None:
# await ctx.voice_client.move_to(channel)
# else:
# await channel.connect()
# await ctx.respond(f"Joined {channel}")
# @bot.command()
# async def leave(ctx):
# if ctx.voice_client is None:
# await ctx.respond("I am not in a voice channel.")
# else:
# await ctx.voice_client.disconnect()
# await ctx.respond("Disconnected")
def AiProcess():
audio_file= open("audio.mp3", "rb")
transcription = client.audio.transcriptions.create(
model="whisper-1",
file=audio_file
)
print(transcription.text)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "Answer with short accurate answers. always answer in english, regardless of the language in which the question was asked"},
{"role": "user", "content": "transcription.text"}
]
)
print(response)
response_text = response.choices[0].message.content
peech_file_path = Path(__file__).parent / "speech.mp3"
response = client.audio.speech.create(
model="tts-1",
voice="nova",
input=response_text
)
output_file_path = "output.mp3"
with open(output_file_path, "wb") as file:
file.write(response.content)
# bot.run(PHOTOBOT_KEY)