Skip to content

Instantly share code, notes, and snippets.

@frivas
frivas / index10.py
Created October 23, 2018 13:05
Objects to Search. Medium Article. Creating an Alexa Skill Using Python
searchObjects = ["bandeja para hacer hielo",
"charco",
"altavoces",
"mando de tv",
"borrador",
"camara fotográfica",
"taza",
"camiseta",
"escritorio",
"patito de goma",
@frivas
frivas / index11.py
Created October 23, 2018 13:05
Adding all the Handlers to the Skill Builder. Medium Article. Creating an Alexa Skill Using Python
sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelAndStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(ListItemsIntent())
sb.add_exception_handler(AllExceptionsHandler())
handler = sb.lambda_handler()
@frivas
frivas / ListItemIntent.json
Last active October 23, 2018 15:03
ListItemsIntent example from Creating an Alexa Skill with Python. Article in Medium
{
"version": "1.0",
"session": {
"new": false,
"sessionId": "amzn1.echo-api.session.123456789012",
"application": {
"applicationId": "amzn1.ask.skill.987654321"
},
"attributes": {},
"user": {
@frivas
frivas / index12.py
Created October 23, 2018 16:28
Import Random. Medium Article on Creating an Alexa Skill with Python
from random import sample
@frivas
frivas / CloudFormation_APIGateway_EU_West_1.json
Last active December 15, 2021 15:15
CloudFormation_APIGateway_EU_West_1.json
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Deploy an HTTP Proxy API Gateway",
"Parameters": {
"AuthorizationURL": {
"Type": "String",
"Default": "<authorization_uri_from_alexa_dev_portal>",
"Description": "URI de Autorización de la sección Account Linking del Portal de Desarrollador de Alexa"
@frivas
frivas / generatePollyMix.py
Last active May 2, 2019 16:08
Mixing Polly with Audip Clip
def generatePollyMix(polly, text, voice, backgroundSFX, format='mp3'):
resp = polly.synthesize_speech(OutputFormat=format, Text=text, VoiceId=voice)
soundfile = open(f"/tmp/sound.mp3", 'wb')
soundBytes = resp['AudioStream'].read()
soundfile.write(soundBytes)
soundfile.close()
audio = MP3("/tmp/sound.mp3")
audio_length = audio.info.length
@frivas
frivas / variables.py
Created May 2, 2019 16:09
Setting up some variables
my_region = 'eu-west-1'
bucket_name = '<bucket_name>'
polly_url = f'https://polly.{my_region}.amazonaws.com/'
s3_url = f'https://s3-{my_region}.amazonaws.com/'
background_file_intro = f"{os.environ['LAMBDA_TASK_ROOT']}/audio/pavane_aws.mp3"
hello_file = f"{os.environ['LAMBDA_TASK_ROOT']}/audio/inspirational_aws.mp3"
@frivas
frivas / prepare_tools.py
Created May 2, 2019 16:26
Prepare Tools
def prepareTools():
exists = os.path.isfile('/tmp/sox')
if not exists:
logger.info('FILE DOES NOT EXISTS')
cp_cmd_output = subprocess.run([f"cp {os.environ['LAMBDA_TASK_ROOT']}/audio/sox /tmp; chmod 755 /tmp/sox"], shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
logger.info(f"CP {cp_cmd_output}")
@frivas
frivas / connect_to_polly.py
Created May 2, 2019 16:27
Connect to Polly
def connectToPolly(regionName=my_region, endpointUrl=polly_url):
return boto3.client('polly', region_name=regionName, endpoint_url=endpointUrl)
@frivas
frivas / get_s3_audio_url.py
Created May 2, 2019 16:29
Get S3 Audio URL
def getS3AudioFile():
s3_filename = hashlib.md5(open('/tmp/output.mp3', 'rb').read()).hexdigest() + '.mp3'
s3.Bucket(bucket_name).upload_file(Filename='/tmp/output.mp3', Key=s3_filename, ExtraArgs={'ACL':'public-read'})
os.remove('/tmp/sound.mp3')
os.remove('/tmp/output.mp3')
return f'<audio src="{s3_url}{bucket_name}/{s3_filename}"/>'