Skip to content

Instantly share code, notes, and snippets.

from polly import Polly
tts = Polly('Joanna')
tts.say('Hi there, I\'m very glad you\'re reading my article. Leave a comment if you find it useful.')
tts.saveToFile('Hi there, save the speech for later', 'joanna.mp3')
@catqbat
catqbat / polly.py
Last active November 29, 2017 16:45
python library for Amazon Polly
import boto3
import pygame
import os
import time
import io
class Polly():
OUTPUT_FORMAT='mp3'
def __init__(self, voiceId):
locationsList.allowsSelection = true;
locationsList.dataSource = mainModel.dataSource!;
locationsList.delegate = mainModel.dataSource!;
locationsList.reloadData();
extension String
{
func width(withConstrainedHeight height: CGFloat, font: UIFont) -> CGFloat
{
let constraintRect = CGSize(width: .greatestFiniteMagnitude, height: height);
let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil)
return boundingBox.width;
}
//Asks the delegate for the size of the specified item’s cell.
//If you do not implement this method, the flow layout uses the values in its itemSize property to set the size of items instead. Your implementation of this method can return a fixed set of sizes or dynamically adjust the sizes based on the cell’s content.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
{
let width = locations[indexPath.row].name.width(withConstrainedHeight: 50, font: LocationCell.locationNameFont);
return CGSize(width: width + 10, height: 50);
}
locationsList.dataSource = mainModel.dataSource!;
locationsList.reloadData();
//Asks your data source object for the number of items in the specified section.
//func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return locations.count;
}
//Asks your data source object for the cell that corresponds to the specified item in the collection view.
//func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
//Asks your data source object for the number of items in the specified section.
//func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return locations.count;
}
//Asks your data source object for the cell that corresponds to the specified item in the collection view.
//func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return locations.count;
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "LocationCell", for: indexPath) as! LocationCell;
let location = locations[indexPath.row];
class LocationDataSource: NSObject, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout
{
let locations: [LocationModel];
let setSelectedLocation: SetLocationDelegate;
init(locations: [LocationModel], delegate: @escaping SetLocationDelegate)
{
self.locations = locations;
self.setSelectedLocation = delegate;
}