mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
Testing for transcribe
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
sudo apt-get install python3-dev
|
||||||
cd /home/pi
|
cd /home/pi
|
||||||
mdkir Conjurer
|
mdkir Conjurer
|
||||||
cd Conjurer
|
cd Conjurer
|
||||||
|
|||||||
@@ -14,5 +14,5 @@ PyNaCl
|
|||||||
flask
|
flask
|
||||||
waitress
|
waitress
|
||||||
clickupython
|
clickupython
|
||||||
assemblyai
|
assemblyai[extras]
|
||||||
git+https://github.com/imayhaveborkedit/discord-ext-voice-recv
|
git+https://github.com/imayhaveborkedit/discord-ext-voice-recv
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
# Start by making sure the `assemblyai` package is installed.
|
||||||
|
# If not, you can install it by running the following command:
|
||||||
|
# pip install -U assemblyai
|
||||||
|
#
|
||||||
|
# Then, make sure you have PyAudio installed: https://pypi.org/project/PyAudio/
|
||||||
|
#
|
||||||
|
# Note: Some macOS users might need to use `pip3` instead of `pip`.
|
||||||
|
|
||||||
|
import pyaudio
|
||||||
|
import assemblyai as aai
|
||||||
|
|
||||||
|
aai.settings.api_key = "aa9962f0088a449a9c4ab2361e96cc08"
|
||||||
|
|
||||||
|
def on_open(session_opened: aai.RealtimeSessionOpened):
|
||||||
|
"This function is called when the connection has been established."
|
||||||
|
|
||||||
|
print("Session ID:", session_opened.session_id)
|
||||||
|
|
||||||
|
def on_data(transcript: aai.RealtimeTranscript):
|
||||||
|
"This function is called when a new transcript has been received."
|
||||||
|
|
||||||
|
if not transcript.text:
|
||||||
|
return
|
||||||
|
|
||||||
|
if isinstance(transcript, aai.RealtimeFinalTranscript):
|
||||||
|
print(transcript.text, end="\r\n")
|
||||||
|
else:
|
||||||
|
print(transcript.text, end="\r")
|
||||||
|
|
||||||
|
def on_error(error: aai.RealtimeError):
|
||||||
|
"This function is called when the connection has been closed."
|
||||||
|
|
||||||
|
print("An error occured:", error)
|
||||||
|
|
||||||
|
def on_close():
|
||||||
|
"This function is called when the connection has been closed."
|
||||||
|
|
||||||
|
print("Closing Session")
|
||||||
|
|
||||||
|
transcriber = aai.RealtimeTranscriber(
|
||||||
|
on_data=on_data,
|
||||||
|
on_error=on_error,
|
||||||
|
sample_rate=44_100,
|
||||||
|
on_open=on_open, # optional
|
||||||
|
on_close=on_close, # optional
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
pa = pyaudio.PyAudio()
|
||||||
|
for i in range(pa.get_device_count()):
|
||||||
|
print (pa.get_device_info_by_index(i))
|
||||||
|
|
||||||
|
# Start the connection
|
||||||
|
#transcriber.connect()
|
||||||
|
|
||||||
|
# Open a microphone stream
|
||||||
|
#microphone_stream = aai.extras.MicrophoneStream()
|
||||||
|
|
||||||
|
# Press CTRL+C to abort
|
||||||
|
#transcriber.stream(microphone_stream)
|
||||||
|
|
||||||
|
#transcriber.close()
|
||||||
@@ -50,7 +50,7 @@ class Transcriber(commands.Cog):
|
|||||||
)
|
)
|
||||||
for utterance in transcript.utterances:
|
for utterance in transcript.utterances:
|
||||||
print(f"Speaker {utterance.speaker}: {utterance.text}")
|
print(f"Speaker {utterance.speaker}: {utterance.text}")
|
||||||
@commands.hybrid_command(name="test")
|
@commands.hybrid_command(name="connect_for_transcribe")
|
||||||
async def test(self, ctx):
|
async def test(self, ctx):
|
||||||
def callback(user, data: voice_recv.VoiceData):
|
def callback(user, data: voice_recv.VoiceData):
|
||||||
print(f"Got packet from {user}")
|
print(f"Got packet from {user}")
|
||||||
@@ -65,11 +65,11 @@ class Transcriber(commands.Cog):
|
|||||||
vc = await ctx.author.voice.channel.connect(cls=voice_recv.VoiceRecvClient)
|
vc = await ctx.author.voice.channel.connect(cls=voice_recv.VoiceRecvClient)
|
||||||
vc.listen(voice_recv.BasicSink(callback))
|
vc.listen(voice_recv.BasicSink(callback))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command(name="stop_transcribe")
|
||||||
async def stop(self, ctx):
|
async def stop(self, ctx):
|
||||||
await ctx.voice_client.disconnect()
|
await ctx.voice_client.disconnect()
|
||||||
|
|
||||||
@commands.command()
|
@commands.command(name="kill_transcribe_client")
|
||||||
async def die(self, ctx):
|
async def die(self, ctx):
|
||||||
ctx.voice_client.stop()
|
ctx.voice_client.stop()
|
||||||
await ctx.bot.close()
|
await ctx.bot.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user