Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Ti 12 #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions example/app/alloy.js
Original file line number Diff line number Diff line change
@@ -1,17 +0,0 @@
// The contents of this file will be executed before any of
// your view controllers are ever executed, including the index.
// You have access to all functionality on the `Alloy` namespace.
//
// This is a great place to do any initialization for your app
// or create any global variables/functions that you'd like to
// make available throughout your app. You can easily make things
// accessible globally by attaching them to the `Alloy.Globals`
// object. For example:
//
// Alloy.Globals.someGlobalFunction = function(){};

(function(){


})();

51 changes: 23 additions & 28 deletions example/app/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
Ti.Media.audioSessionCategory = Titanium.Media.AUDIO_SESSION_CATEGORY_PLAY_AND_RECORD;

var TiSpeech = require('ti.speech');
TiSpeech.initialize();

var canRecordAudio = false;
var canUseSpeechRecognition = false;
var isRunning = false;

if (!TiSpeech.isAvailable()) {
alert('Speech recognition is not available on this device!');
} else {
TiSpeech.requestSpeechRecognizerAuthorization(function(e) {
canUseSpeechRecognition = !!e.success;
if (!e.success) {
alert("Speech recognition was not authorized!");
} else {
TiSpeech.requestMicrophoneAuthorization(function(e) {
canRecordAudio = !!e.success;
if (!e.success) {
alert("Permission to record audio was not authorized!");
}
enableButtons();
});
}
});
}

Ti.Media.requestAudioRecorderPermissions(function(e){
if (e.success) {
if (!TiSpeech.isAvailable()) {
alert('Speech recognition is not available on this device!');
} else {
enableButtons();
}
}
});


/**
* @function enableButtons
* @summary Enable buttons based on permissions granted by user
* @since 1.0.0
*/
function enableButtons() {
canUseSpeechRecognition && canRecordAudio && $.toggleLiveRecognitionButton.setEnabled(true);
canUseSpeechRecognition && $.toggleAudioRecognitionButton.setEnabled(true);
canUseSpeechRecognition && $.toggleVideoRecognitionButton.setEnabled(true);
$.toggleLiveRecognitionButton.enabled = true;
$.toggleAudioRecognitionButton.enabled = true;
$.toggleVideoRecognitionButton.enabled = true;
}

/**
Expand All @@ -52,9 +47,9 @@ function stopRecognition() {
$.toggleAudioRecognitionButton.title = 'Start Listening to Audio File';
$.toggleVideoRecognitionButton.title = 'Start Listening to Video File';

$.toggleLiveRecognitionButton.setEnabled(true);
$.toggleAudioRecognitionButton.setEnabled(true);
$.toggleVideoRecognitionButton.setEnabled(true);
$.toggleLiveRecognitionButton.enabled = true;
$.toggleAudioRecognitionButton.enabled = true;
$.toggleVideoRecognitionButton.enabled = true;
}

/**
Expand All @@ -78,7 +73,7 @@ function progressCallback(result) {
stopRecognition();
return;
} else {
$.results.setText(result.value);
$.results.text = result.value;
}
if (result.finished) {
isRunning = false;
Expand All @@ -92,7 +87,7 @@ function toggleLiveRecognition(e) {
if (isRunning) {
stopRecognition();
} else {
$.results.setText('Listening...');
$.results.text = 'Listening...';

var success = TiSpeech.startRecognition({
progress: progressCallback,
Expand All @@ -112,7 +107,7 @@ function toggleAudioRecognition(e) {
if (isRunning) {
stopRecognition();
} else {
$.results.setText('Loading Audio File...');
$.results.text = 'Loading Audio File...';
var success = TiSpeech.startRecognition({
type: TiSpeech.SOURCE_TYPE_URL,
url: 'one_more_thing.mp3',
Expand All @@ -132,7 +127,7 @@ function toggleVideoRecognition(e) {
if (isRunning) {
stopRecognition();
} else {
$.results.setText('Loading Video File...');
$.results.text = 'Loading Video File...';

var success = TiSpeech.startRecognition({
type: TiSpeech.SOURCE_TYPE_URL,
Expand Down
30 changes: 10 additions & 20 deletions example/app/lib/ti.speech.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,11 @@
* @version 1.0.0
* @since 1.0.0
*/

var AVAudioEngine = require('AVFoundation/AVAudioEngine');
var AVAudioSession = require('AVFoundation/AVAudioSession');
var AVFoundation = require('AVFoundation');
var NSBundle = require('Foundation/NSBundle');
var NSError = require('Foundation/NSError');
var NSLocale = require('Foundation/NSLocale');
var NSURL = require('Foundation/NSURL');
var SFSpeechAudioBufferRecognitionRequest = require('Speech/SFSpeechAudioBufferRecognitionRequest');
var SFSpeechRecognitionRequest = require('Speech/SFSpeechRecognitionRequest');
var SFSpeechRecognitionResult = require('Speech/SFSpeechRecognitionResult');
var SFSpeechRecognitionTask = require('Speech/SFSpeechRecognitionTask');
var SFSpeechRecognizer = require('Speech/SFSpeechRecognizer');
var SFSpeechURLRecognitionRequest = require('Speech/SFSpeechURLRecognitionRequest');
var Speech = require('Speech');
import { AVAudioEngine } from 'AVFAudio';
import { AVAudioSession, AVFoundation } from 'AVFoundation';
import { NSBundle, NSError, NSLocale, NSURL } from 'Foundation';
import { SFSpeechAudioBufferRecognitionRequest, SFSpeechRecognitionRequest,SFSpeechRecognitionResult,
SFSpeechRecognitionTask, SFSpeechRecognizer, SFSpeechURLRecognitionRequest, Speech } from 'Speech';

var audioEngine;
var request;
Expand Down Expand Up @@ -64,7 +54,7 @@ exports.initialize = function(locale) {
/**
* @function requestSpeechRecognizerAuthorization
* @summary Asks the user to grant your app permission to perform speech recognition.
* @param {permissionCallback} callback - A function that is called when the authorization request has been approved or denied.
* @param {permissionCallback} callback - A function that is called when the authorization request has been approved or denied.
* @since 1.0.0
*/
exports.requestSpeechRecognizerAuthorization = function(callback) {
Expand Down Expand Up @@ -114,7 +104,7 @@ exports.requestSpeechRecognizerAuthorization = function(callback) {
/**
* @function requestMicrophoneAuthorization
* @summary Asks the user to grant your app permission to record audio using microphone.
* @param {permissionCallback} callback - A function that is called when the authorization request has been approved or denied.
* @param {permissionCallback} callback - A function that is called when the authorization request has been approved or denied.
* @since 1.0.0
*/
exports.requestMicrophoneAuthorization = function(callback) {
Expand Down Expand Up @@ -161,7 +151,7 @@ exports.requestMicrophoneAuthorization = function(callback) {

/**
* Indicates whether the speech recognizer is available.
* Even though a speech recognizer is supported for a specific locale,
* Even though a speech recognizer is supported for a specific locale,
* it might be unavailable for reasons such as a nonfunctioning Internet connection.
* @function isAvailable
* @summary Indicates whether the speech recognizer is available.
Expand Down Expand Up @@ -196,13 +186,13 @@ exports.isAvailable = function() {
exports.startRecognition = function(args) {
var progressCallback = args.progress || null;
var type = args.type;

if (!type && args.url) {
type = SOURCE_TYPE_URL;
} else if (!type) {
type = SOURCE_TYPE_MICROPHONE;
}

if (!progressCallback) {
Ti.API.error('No "progress" callback supplied - You will not be notified about transcription updates');
}
Expand Down
5 changes: 2 additions & 3 deletions example/app/views/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
<Label top="20">Transcription:</Label>
<View>
<ScrollView width="fill" height="fill" contentWidth="fill" backgroundColor="#252526" borderRadius="10" top="15" left="15" right="15" bottom="15">
<Label id="results" height="size" width="fill" top="15" top="15" left="15" right="15" bottom="15" color="white" verticalAlign="Titanium.UI.TEXT_VERTICAL_ALIGNMENT_TOP"
/>
<Label id="results" height="size" width="fill" top="15" left="15" right="15" bottom="15" color="white" verticalAlign="Titanium.UI.TEXT_VERTICAL_ALIGNMENT_TOP"/>
</ScrollView>
</View>
</Window>
</NavigationWindow>
</Alloy>
</Alloy>
43 changes: 24 additions & 19 deletions example/plugins/ti.alloy/hooks/alloy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Alloy
* Copyright (c) 2012 by Appcelerator, Inc. All Rights Reserved.
* Copyright TiDev, Inc. 04/07/2022-Present
* See LICENSE for more information on licensing.
*/

exports.cliVersion = '>=3.X';
exports.version = '1.0.0';
exports.version = '1.0.1';
var SILENT = true;

exports.init = function (logger, config, cli, appc) {
Expand All @@ -20,9 +20,9 @@ exports.init = function (logger, config, cli, appc) {
spawn = require('child_process').spawn,
parallel = appc.async.parallel;

if(!process.env.sdk) {
process.env.sdk = cli.sdk.name;
}
if (!process.env.sdk) {
process.env.sdk = cli.sdk.name;
}

function run(deviceFamily, deployType, target, finished, silent) {
var appDir = path.join(cli.argv['project-dir'], 'app');
Expand Down Expand Up @@ -50,12 +50,16 @@ exports.init = function (logger, config, cli, appc) {
deploytype: deployType || cli.argv['deploy-type'] || 'development',
target: target
};
if(silent) {
if (silent) {
// turn off all logging output for code analyzer build hook
config.noBanner = 'true';
config.logLevel = '-1';
}

if (cli.argv.theme) {
config.theme = cli.argv.theme;
}

config = Object.keys(config).map(function (c) {
return c + '=' + config[c];
}).join(',');
Expand Down Expand Up @@ -119,6 +123,12 @@ exports.init = function (logger, config, cli, appc) {
};
}), function () {

if (!paths.alloy) {
logger.error('The alloy CLI is not installed');
logger.error('Please install it with [sudo] npm i alloy -g');
process.exit(1);
}

// compose alloy command execution
var cmd = [paths.node, paths.alloy, 'compile', appDir, '--config', config];
if (cli.argv['no-colors'] || cli.argv['color'] === false) { cmd.push('--no-colors'); }
Expand All @@ -145,17 +155,16 @@ exports.init = function (logger, config, cli, appc) {
if (process.platform === 'win32' && paths.alloy === 'alloy.cmd') {
cmd.shift();
logger.info(__('Executing Alloy compile: %s',
['cmd','/s','/c'].concat(cmd).join(' ').cyan));
['cmd', '/s', '/c'].concat(cmd).join(' ').cyan));

// arg processing from https://github.com/MarcDiethelm/superspawn
child = spawn('cmd', [['/s', '/c', '"' +
cmd.map(function(a) {
if (/^[^"].* .*[^"]/.test(a)) return '"'+a+'"'; return a;
}).join(" ") + '"'].join(" ")], {
stdio: 'inherit',
windowsVerbatimArguments: true
}
);
if (/^[^"].* .*[^"]/.test(a)) return '"' + a + '"'; return a;
}).join(' ') + '"'].join(' ')], {
stdio: 'inherit',
windowsVerbatimArguments: true
});
} else {
logger.info(__('Executing Alloy compile: %s', cmd.join(' ').cyan));
child = spawn(cmd.shift(), cmd);
Expand All @@ -175,8 +184,8 @@ exports.init = function (logger, config, cli, appc) {
} else {
logger.info(__('Alloy compiler completed successfully'));

afs.exists(path.join(cli.argv["project-dir"], 'build', 'i18n')) && process.argv.push('--i18n-dir', 'build');
afs.exists(path.join(cli.argv["project-dir"], 'build', 'platform')) && (cli.argv['platform-dir'] = 'build/platform');
afs.exists(path.join(cli.argv['project-dir'], 'build', 'i18n')) && process.argv.push('--i18n-dir', 'build');
afs.exists(path.join(cli.argv['project-dir'], 'build', 'platform')) && (cli.argv['platform-dir'] = 'build/platform');
}
finished();
});
Expand All @@ -191,8 +200,4 @@ exports.init = function (logger, config, cli, appc) {

run(build.deviceFamily, deployType, target, finished);
});

cli.addHook('codeprocessor.pre.run', function (build, finished) {
run('none', 'development', undefined, finished, SILENT);
});
};
7 changes: 3 additions & 4 deletions example/plugins/ti.alloy/hooks/deepclean.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Alloy
* Copyright (c) 2014 by Appcelerator, Inc. All Rights Reserved.
* Copyright TiDev, Inc. 04/07/2022-Present
* See LICENSE for more information on licensing.
*/

Expand All @@ -13,7 +13,7 @@ exports.init = function (logger, config, cli, appc) {
afs = appc.fs;

function run(finished) {
if(cli.argv['shallow'] === '') {
if (cli.argv['shallow'] === '') {
logger.info('Not cleaning the Resources directory');
finished();
return;
Expand Down Expand Up @@ -46,8 +46,7 @@ function rmdir(dirPath, fs, path, logger, removeSelf) {
var files;
try {
files = fs.readdirSync(dirPath);
}
catch(e) {
} catch (e) {
return;
}
if (files.length > 0) {
Expand Down
9 changes: 3 additions & 6 deletions example/tiapp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,16 @@
</plist>
</ios>
<modules>
<module platform="iphone" version="2.0.1">hyperloop</module>
<module platform="commonjs">ti.cloud</module>
<module platform="iphone">com.appcelerator.apm</module>
<module>hyperloop</module>
</modules>
<deployment-targets>
<target device="android">false</target>
<target device="ipad">true</target>
<target device="iphone">true</target>
<target device="mobileweb">false</target>
</deployment-targets>
<sdk-version>6.0.3.GA</sdk-version>
<sdk-version>12.0.0.GA</sdk-version>
<plugins>
<plugin version="1.0">ti.alloy</plugin>
<plugin version="2.0.1">hyperloop</plugin>
</plugins>
</ti:app>
</ti:app>
1 change: 0 additions & 1 deletion ti.speech.js

This file was deleted.

Loading