Skip to content

Commit

Permalink
Added starter code for speech input and output and renamed repo name …
Browse files Browse the repository at this point in the history
…in update_leaderboard script.
  • Loading branch information
Sammybams committed Sep 25, 2024
1 parent 57eae2f commit bdee69d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
80 changes: 80 additions & 0 deletions src/speech_io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os
import requests
import azure.cognitiveservices.speech as speechsdk
from dotenv import load_dotenv
load_dotenv()

# Define the endpoint and subscription key
url = f"https://eastus.api.cognitive.microsoft.com/speechtotext/transcriptions:transcribe?api-version=2024-05-15-preview"
subscription_key = os.getenv('SUBSCRIPTION_KEY')


## TRANSCRIPTION - Fast Transcription with Azure Speech Service

# Set up headers with your subscription key
# subscription_key = 'YourSubscriptionKey'
headers = {
'Ocp-Apim-Subscription-Key': subscription_key,
'Accept': 'application/json'
}

# Define the files and data for the request
files = {
'audio': open("audio.wav", 'rb') # Replace with your audio file path
}
data = {
'definition': '''
{
"locales": ["en-US"],
"profanityFilterMode": "Masked"
}
'''
}
# "channels": [0, 1]

# Make the POST request
response = requests.post(url, headers=headers, files=files, data=data)

# Check the response
if response.status_code == 200:
print('Success!')
print(response.json())
print(response.json()['combinedPhrases'][0]['text'])
else:
print('Error:', response.status_code)
print("\n" + response.text)
error_message = "Error: " + str(response.status_code) + "\n" + response.text
raise Exception(error_message)






## SPEECH SYNTHESIS - Speech Synthesis/Generation with Azure Speech Service

text = "I love the AI Hacktoberfest challenge by MLSA Nigeria!"

# This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
speech_config = speechsdk.SpeechConfig(subscription=os.getenv("SPEECH_KEY"), region=os.getenv("SPEECH_REGION"))
audio_config = speechsdk.audio.AudioOutputConfig(filename="output.wav")
# audio_config = speechsdk.audio.AudioOutputConfig(filename="output.wav")

# The neural multilingual voice can speak different languages based on the input text.
speech_config.speech_synthesis_voice_name='en-NG-EzinneNeural'

speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)

speech_synthesis_result = speech_synthesizer.speak_text_async().get()

if speech_synthesis_result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
print("Speech synthesized for text [{}]".format(text))

elif speech_synthesis_result.reason == speechsdk.ResultReason.Canceled:
cancellation_details = speech_synthesis_result.cancellation_details
print("Speech synthesis canceled: {}".format(cancellation_details.reason))
if cancellation_details.reason == speechsdk.CancellationReason.Error:
if cancellation_details.error_details:
print("Error details: {}".format(cancellation_details.error_details))
print("Did you set the speech resource key and region values?")

4 changes: 2 additions & 2 deletions update_leaderboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def initialize_api():
# Define your GitHub repository and authentication token
repository_owner = "mlsanigeria"
repository_name = "AI-Hacktober-MLSA"
repository_name = "speak-to-docs"
api_token = os.environ.get("API_TOKEN")

# Define the GitHub API endpoint for pull requests
Expand Down Expand Up @@ -54,7 +54,7 @@ def get_sorted_pr():
merged_prs_count_by_user = defaultdict(int)
avi = {}
# Create a list of contributors to exempt
exempt = ["Odion-Sonny", "Tutu6790", "Sammybams", "FelixFrankFelix", "Olamilekan002", "AjibolaMatthew1", "salimcodes"]
exempt = []

# Iterate through the pull_requests list
for pr in response:
Expand Down

0 comments on commit bdee69d

Please sign in to comment.